Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery. Select all elements with a class but without style="display:none;" attribute

I have the following class, which selects what's inside of the td.lineitemtotal cells and uses it in the getTotal function to get a total of the cells. But, I don't want the function to use the lines that are in a 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));
}
like image 514
leonel Avatar asked Sep 20 '12 17:09

leonel


People also ask

Is jQuery hide the same as display none?

jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page).


3 Answers

Do you want this ?

$('.lineitemtotal:visible');

This set contains the not hidden elements having class lineitemtotal.

like image 196
Denys Séguret Avatar answered Sep 29 '22 12:09

Denys Séguret


var line_totals = $('.lineitemtotal:not([style*="display:none"])');
like image 25
Phillip Schmidt Avatar answered Sep 29 '22 12:09

Phillip Schmidt


On your selector include the :visible selector:

$('.lineitemtotal:visible');
like image 38
John Koerner Avatar answered Sep 29 '22 10:09

John Koerner