[英]How can I make the entire parent element of an anchor clickable?
我几乎达到了预期的目标,但是在注入代码后页面重新加载了两次。 重新加载是不希望的。
<script>
$("#block-yui_3_17_2_1_1548947018047_6823").click(function() {
window.location = $(this).find("a").attr("href");
return false;
});
</script>
页面的URL: https ://goodbrother.squarespace.com/blog/标题为“生产团队中的谁”的顶部图像div是使用此代码的div。
您将返回带有find('a')
的数组。 您需要指定一个元素。 它可能与find('a')[0]
,但是最好将一个类放在锚上并对其进行定位。
我可以通过将一个类添加到“ a”来解决
<script>
$("#block-yui_3_17_2_1_1548947018047_6823").click(function() {
window.location = $(this).find("a.image-overlay").attr("href");
return false;
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.