开发者

Jquery exclude element that not have <a href="#"> inside

how can I exclude from this selection element that not have a href="#" inside of it? I want my stuff is executed only for .leading that have a href="#"... thank you

//js
$(".leading").hover(function(){
// do stuff
}

//DOM
<div class=".leading"><div ><a href="#"> <img src="img1.jpg" /> jquery affected </a></div></div>
<div class=".leading"><div ><img src="img2.jpg"开发者_如何学Go /> jquery not affected </div></div>


Something like this I believe:

$('.leading:has(a[href=#])');

Note, your classes should not have a dot . prefix in the HTML itself.


$("div.leading div a[href='#']")

... will select only those anchor tags with a href attribute set to the value #.

You can then use .parent().parent() to walk up to the div.leading element.

Also in your example HTML you are using .leading as a class name which is invalid, it should be leading.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜