Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery href click - how can I fire up an event?

I have this anchor and on click I would like to popup something. This href is within a page that has other hrefs.

<a class="sign_new" href="#sign_up">Sign up</a>

jQuery:

$(document).ready(function(){
   $('a[href = "sign_up"]').click(function(){
      alert('Sign new href executed.'); 
   }); 
});

The above code does not fire up.

like image 495
user1965451 Avatar asked Jan 14 '13 21:01

user1965451


People also ask

How do you trigger an event on click?

If you just need to trigger a click event, you can omit the line that begins with for( . @Parag: Read it again. The loop is to click the same link 50 times, which is what it does.

How do you trigger a click event for a hyperlink?

Answer: Use the jQuery click() Method You can use the click() method to trigger a click on a link programmatically using jQuery.

How do I trigger a click event without clicking?

If you want native JS to trigger click event without clicking then use the element id and click() method of JavaScript.


1 Answers

It doesn't because the href value is not sign_up.It is #sign_up. Try like below, You need to add "#" to indicate the id of the href value.

$('a[href="#sign_up"]').click(function(){
  alert('Sign new href executed.'); 
}); 

DEMO: http://jsfiddle.net/pnGbP/

like image 156
Selvakumar Arumugam Avatar answered Oct 15 '22 21:10

Selvakumar Arumugam