I am trying to hide all $0.00
strings from a page and tried but did not succeeded. I get error: TypeError: hidepricenull.each is not a function
. I am using it in wordpress.
HTML
<span class="amount">£200.00</span>
<span class="amount">£200.00</span>
Jquery
jQuery(document).ready(function($) {
var hidepricenull = $('span.amount').text();
hidepricenull.each(function() {
if(hidepricenull == '£200.00') {
$(this).hide();
}
});
});
Expected Output:
Hide the 2 text from spans
<span class="amount"></span>
<span class="amount"></span>
Your
hidepricenull
value is a string (the first item’s text value, because of callingtext()
) but you need the collection and access the text per item:Note you could also start using the rather handy scoping DOM-ready shortcut for jQuery:
Note the temp variable is no longer required and you can use a filter instead:
Update to support multiple values:
Update to support numeric comparisons (faster than strings for many values):
You should iterate over the items and check for it’s text, you could try this:
by using jquery u can do it simply