How to check attr class for string?
How to check at开发者_Python百科tr class for string?
E.G.
HTML:
<p class="p_header"></p>
How to check that 'p'
has in it's class '_header'
string?
Any suggestions much appreciated.
$("p[class$='_header']")
OR
$("p[class*='_header']")
Use ......className.indexOf('_header') != -1
Do you need more details than that?
If you wanna check for a string within a p's class, you may use a simple search. Say you have your 'p' inside a div.
$('#your_div p').first().attr('class').search("_header")
This returns -1 if false or no match found, & index if true or match found.
OR you can directly access your 'p' using other answers submitted here.
精彩评论