Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使第n个子分区中的图像成为点击链接_Javascript_Jquery_Html_Squarespace - Fatal编程技术网

Javascript 使第n个子分区中的图像成为点击链接

Javascript 使第n个子分区中的图像成为点击链接,javascript,jquery,html,squarespace,Javascript,Jquery,Html,Squarespace,我正在尝试使用jquery在我的squarespace站点上添加到几个图像的链接。然而,他们不共享一个类,我不能添加一个,因为我使用squarespace,所以我只能添加自定义css或javascript 因此,我尝试这样做的方式是选择父div,它具有类名.ProductItem gallery slides item,然后是它的第二个子div,也是一个div,然后是其中的图像。一旦我选择了正确的元素,我就添加了一个点击功能,该功能应该链接到一个包含更多图像信息的页面。我已经尝试了另一种使用.w

我正在尝试使用jquery在我的squarespace站点上添加到几个图像的链接。然而,他们不共享一个类,我不能添加一个,因为我使用squarespace,所以我只能添加自定义css或javascript

因此,我尝试这样做的方式是选择父div,它具有类名.ProductItem gallery slides item,然后是它的第二个子div,也是一个div,然后是其中的图像。一旦我选择了正确的元素,我就添加了一个点击功能,该功能应该链接到一个包含更多图像信息的页面。我已经尝试了另一种使用.warp的方法,但我对jquery非常陌生,我不太了解它,也不太管用

html层次结构:

<div class="ProductItem-gallery-slides-item">
  <div>
    <img 1>
  </div>
  <div>
    <img 2>
  </div>
</div>
结果应该是一个可点击的图像


希望我问对了,非常感谢大家的问候。您的选择器不正确。使用

$(".ProductItem-gallery-slides-item > div:nth-child(2) > img").on("click", ...
因为您想要获取ProductItem gallery幻灯片项目的第二个子div

此外,您的代码缺少结束符。还有一个旁注:$。单击。。。不推荐使用。使用$.onclick。。。请参阅下面的代码

演示:

$document.readyfunction{ $.ProductItem库幻灯片项目>div:nth-child2>img.onclick,函数{ //window.location=https://uk5-shop.com/paris-pink'; //用于演示的console.log console.logSecond图像已单击!; }; };
$(".ProductItem-gallery-slides-item > div:nth-child(2) > img").on("click", ...