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));
}
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));
}
Share
Improve this question
asked Sep 20, 2012 at 17:08
leonelleonel
10.2k21 gold badges87 silver badges129 bronze badges
4 Answers
Reset to default 11Do you want this ?
$('.lineitemtotal:visible');
This set contains the not hidden elements having class lineitemtotal
.
var line_totals = $('.lineitemtotal:not([style*="display:none"])');
On your selector include the :visible selector:
$('.lineitemtotal:visible');
If you know for certain that the attribute will always be style="display:none;"
you can use an attribute selector.
Instead of this:
var line = $('.item');
Try this:
var line = $('.item[style!="display:none;"]');
using [attribute="value"]
looks for elements that have attribute
with value value
, adding the !
before the =
looks for things that do NOT match.