javascript - jQuery Div OnClick 触发兄弟链接

标签 javascript jquery html siblings

我将如何制作 <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/

相关文章:

javascript - findTwins,它接受一个整数数组并找到两个相同的数字并返回重复两次的数字

javascript - 为什么我的 jQuery 动画不能正常工作?

javascript - 如何使用dom jquery在html页面中显示值

html - 为什么我的网站在 iPad 上只显示一张图片?

javascript - AngularJS TypeScript 单元测试

javascript - 同时淡入淡出

javascript - 在 TinyMCE 编辑器中解开图像中的 p 标签

jquery - 在 iOS 设备上关闭 CSS 菜单

html - 我的页面左上角有这个 DIV。我怎样才能制作一个填充这个 div 的 anchor ?

javascript - 尝试将数据从类保存到 localStorage 中