我的帖子里面有一张图片。它们显示在我网站的主页上。每个帖子都有一张图片,一个关于帖子的描述,以及一个“更多”按钮,它将用户带到完整的文章。
我的问题是我想将图像链接到完整的帖子。我希望图像作为“更多”按钮。
我已经尝试过使用jQuery,wrap()函数,链接文章本身的图像,到目前为止还没有任何结果。
图像的代码只是:
<img src="random.jpg" class="YTimgs">
有谁知道我怎么能让这个工作?我一直在研究这个问题,但没有找到正确的解决方案。我希望有人帮助我。
更新小提琴:http://jsfiddle.net/5md7p9L7/7/
<img src="http://lorempixel.com/400/200/"/>
<a class="link" href="http://google.com" target="_blank">The picture and this text are both links to the same page :)</a>
jQuery的
$('img').click(function(){
var link =$(this).next().attr('href');
window.open(link);
});
你的一些图像有YTimg类,其他图像有YTimgs ...只给它一个类:
$(document).on("click", "img.YTimgs", function(){
$(this).closest("div.post").find(".jump-link").find("a").trigger("click");
});
这应该是棘手的