jQuery选择器:只与内部的图像链接 [英] jQuery selectors: only link with images inside them

查看:113
本文介绍了jQuery选择器:只与内部的图像链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用某种灯箱打开图像,例如colorbox。如何才能打开链接,其中有图像,并在.content类?

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?

类似于:

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


推荐答案

您可以使用 :has()选择器

You can use the :has() selector:

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






如果您已经有一个jQuery对象 $('。content a')包含您也可以调用 .has('img')的所有链接以减少它的元素就像选择器一样。


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.

这篇关于jQuery选择器:只与内部的图像链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆