Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  52] [ 4]  / answers: 1 / hits: 16457  / 10 Years ago, sat, august 2, 2014, 12:00:00

I am trying to click a href element on my html website. Problem is that click event is not triggered



CODE:



HTML CODE:



  <div class=button id=info ></div>
<ul id=game-options>

<li><a href=# id=SHOW_HELP class=button help title=Help>HELP</a></li>
</ul>


Function that clicks a href element:



 $('#info').bind('click', function(e) {
alert (button click triggered);
// This is what I tried so fat

//$('#SHOW_HELP').trigger('click');
//$('#SHOW_HELP').dispatchEvent(new Event('click'));
$('#SHOW_HELP').click();
});

More From » jquery

 Answers
25

The click event is triggered, but you haven't bound a click handler so nothing will happen. If you want to simulate clicking the link you need to use the dom click method, ie. $('#SHOW_HELP')[0].click();


[#69941] Thursday, July 31, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxinec

Total Points: 117
Total Questions: 116
Total Answers: 116

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
maxinec questions
;