Badr Hari
Badr Hari

Reputation: 8414

jQuery selectors: only link with images inside them

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();

Upvotes: 1

Views: 927

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318518

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.

Upvotes: 7

Related Questions