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));
}
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).
Do 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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With