Problem when filtering a selection with jQuery
$("[title != '' ]").each(function(){开发者_运维知识库
$(this).addClass('lkBox');
});
I´ve been programming some stuffs in my job and i used to filter empty title elements by the script over this text. Is it correctly? I tested in my localserver with a simple HTML page that i mounted and everthing was ok.
Yes it is correct. You are using the Not Equal Selector
The only difference between your example and jQuery documentation is that they switch the single quotes and double quotes, and they don't have spaces, so try this:
$('[title!=""]').each(function(){
$(this).addClass('lkBox');
});
Alternatively, check that the titles on the page it is not working on are actually empty.
If you don't have a place to test (your website etc.), use online resources like jsfiddle
, there you can do simple examples and see if it worked
精彩评论