开发者

How to check attr class for string?

开发者 https://www.devze.com 2023-03-24 00:42 出处:网络
How to check at开发者_Python百科tr class for string? E.G. HTML: <p class=\"p_header\"></p>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消