jQuery选择器:只链接其中的图像

Bad*_*ari 1 html jquery jquery-selectors colorbox

我想用某种灯箱,彩盒打开图像.怎么可能只打开里面有图像并且在.content类中的链接?

就像是:

$('.content a img').colorbox();
Run Code Online (Sandbox Code Playgroud)

Thi*_*ter 7

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

$('.content a:has(img)').colorbox();
Run Code Online (Sandbox Code Playgroud)

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