jQuery selectors: only link with images inside the

2019-08-07 06:42发布

I want to open images with some kind of lightbox, colorbox for an example. How would it be possible to open only link which have images inside them and are in .content class?

Something like:

$('.content a img').colorbox();

1条回答
做自己的国王
2楼-- · 2019-08-07 07:30

You can use the :has() selector:

$('.content a:has(img)').colorbox();

In case you already have a jQuery object $('.content a') containing all links you could also call .has('img') on it to reduce its elements just like the selector would do.

查看更多
登录 后发表回答