[英]jQuery on click fire second child
I'm trying to make a div have an on click function that opens the link assigned to an <a>
inside of it. 我正在尝试让div有一个on click函数,打开分配给它内部的
<a>
的链接。 I've tried a few variations of this, but nothing seems to be working correctly. 我尝试了一些这方面的变化,但似乎没有任何正常工作。
My jQuery 我的jQuery
$('div#task_list').delegate("div.task_bucket", "click", function() {
$(this + ' div.task_name a.show_task_link').click();
})
And my HTML 还有我的HTML
<div class="grid_3 border_box task_bucket">
<div class="date border_box">
November 16, 2012
<span class="comments">3</span>
</div>
<div class="task_name">
<a href="/tasks/165" class="show_task_link" data-remote="true" id="165">Lorem Ipsum Dolor sit amen...</a>
</div>
</div>
您需要将this
用作上下文
$('div.task_name a.show_task_link',this).click();
I'd suggest, given that this seems required to open a new page (since the href
isn't preceded by a #
character, that would suggest moving within the current page): 我建议,鉴于这似乎需要打开一个新页面(因为
href
前面没有#
字符,建议在当前页面内移动):
$('#task_list').on('click', 'a', function(e){
window.location = e.target.href;
});
尝试$('.task_name a').click()
$('div.tlist').click(function(){
var x= $('div.tlist').find('a').attr('href');
window.open(x);
});
Use find method to get the child attribute.. 使用find方法获取子属性..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.