This is driving me nuts… But I surely miss something.
So the HTML looks like:
<ul>
<li><span>Product spec name</span><span>232112412</span></li>
<li><span>Product spec name</span><span>cm</span></li>
<li><span>Product spec name</span><span>80 cm</span></li>
<li><span>Product spec name</span><span>75 cm</span></li>
<li><span>Product spec name</span><span>cm</span></li>
</ul>
So what I want to achieve is to hide those list elements where the second span contains less than or equal to 2 characters.
I thought about putting them into a variable, loop through them, and if the length of the current item is less than or equal to 2 then jQuery should hide its parent.
Heres the code I wrote:
$(document).ready(function () {
var pspec = $('ul li span:nth-child(2)');
for(i=0;i<pspec.length;i++) {
if($(pspec[i]).text().length <= 2) {
$(this).parent().hide();
}
}
});
But this code won’t do the trick… I still consider myself a jQuery beginner so please would You be so kind to help me out on this one?
Thanks in advance!
Best Wishes,
Matt
Demo: http://jsfiddle.net/PFaav/
Your code will work if you replace
by this