Reputation: 512
I'm trying to make a div have an on click function that opens the link assigned to an <a>
inside of it. I've tried a few variations of this, but nothing seems to be working correctly.
My jQuery
$('div#task_list').delegate("div.task_bucket", "click", function() {
$(this + ' div.task_name a.show_task_link').click();
})
And my 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>
Upvotes: 0
Views: 118
Reputation: 1152
$('div.tlist').click(function(){
var x= $('div.tlist').find('a').attr('href');
window.open(x);
});
Use find method to get the child attribute..
Upvotes: 0
Reputation: 253486
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):
$('#task_list').on('click', 'a', function(e){
window.location = e.target.href;
});
Upvotes: 0
Reputation: 33661
You need to use this
as the context
$('div.task_name a.show_task_link',this).click();
Upvotes: 2