JQuery Select all elements with a class but no style = "display: none;" attribute

I have the following class that selects what's inside td.lineitemtotal cells and uses it in the getTotal function to get the total number of cells. But I do not want the function to use lines that are in tr.line_item_row with style = "display: none;" attribute.

$(document).ready(function() {
  var line = $('.item');
  // so the line totals are calculated on page load
  getLineItemTotals(line);

  var line_totals = $('.lineitemtotal');
  getTotal(line_totals); // So the total is calculated on page load.
});

// get invoce grand total
function getTotal(lines) {
  var total = 0;
  $.each(lines, function(){
    total += parseFloat($(this).html());
  });
  $('#total-price').html('$' + total.toFixed(2));
}
+5
source share
4 answers

Do you want it

$('.lineitemtotal:visible');

This set contains non-hidden elements that have a class lineitemtotal.

+10
source
var line_totals = $('.lineitemtotal:not([style*="display:none"])');
+4
source

: visible :

$('.lineitemtotal:visible');
+2

, style="display:none;", .

:

var line = $('.item');

:

var line = $('.item[style!="display:none;"]');

[attribute="value"] attribute value, !, = , .

+2
source

All Articles