我将如何制作 <div class="hover"></div>
单击触发器 <a href="http://example.com" target="_blank">
?我试过使用同级选择器,但我似乎无法掌握它的窍门..
当有人点击 div.hover 时,我需要使用兄弟 anchor 的 href 打开一个新窗口。
<ul id="photoUL">
<li>
<div class="hover"></div>
<a href="http://example.com" target="_blank">
<img width="150" height="150" style="border: 1px solid #000000;" title="2013 Dirty Duathlon" src="http://example.com/example.jpg">
</a>
<a href="http://example.com" target="_blank">EXAMPLE</a>
</li>
最佳答案
$('div.hover').on('click',function(){
window.location.href = $(this).next('a').attr('href');
});
演示 --->
http://jsfiddle.net/NGwL9/
关于javascript - jQuery Div OnClick 触发兄弟链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17199660/