nathan
nathan

Reputation: 512

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. 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

Answers (4)

Darknight
Darknight

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

Bull
Bull

Reputation: 701

Try $('.task_name a').click()​.

Upvotes: 0

David Thomas
David Thomas

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

wirey00
wirey00

Reputation: 33661

You need to use this as the context

$('div.task_name a.show_task_link',this).click();

Upvotes: 2

Related Questions