I have a number of elements with a certain class and am trying to append something to them should a certain condition be true. Here is an example, but it tells me this.value() is not a function. I am not sure how to refer to an individual element using jquery.
<span class="numbers">1</span><br>
<span class="numbers">2</span><br>
<span class="numbers">3</span><br>
$('.numbers').after(function() {
if (this.value() > 1) return ('<span>Bigger than one.</span>');
});
You had a few problems.
First, you need to refer to
$(this)instead ofthisto use a jQuery function on it.Second, use
.text()to get the value of the element as text.The parseInt(value, 10) is just a good idea when comparing text to a number in javascript.