Page 1 of 1
click handler on a link
Posted: Wed Jun 13, 2012 3:25 pm
by Live24x7
While I could manage to use a handler on a submit button - it is not working on links
How do i add a click handler on a link .
Re: click handler on a link
Posted: Wed Jun 13, 2012 3:46 pm
by pickle
Using just raw Javascript? jQuery? MooTools?
How are you adding your handler to the button?
Re: click handler on a link
Posted: Wed Jun 13, 2012 4:07 pm
by Live24x7
sorry - i am still fiddling with all these - but the case in question is jQuery
Re: click handler on a link
Posted: Wed Jun 13, 2012 4:35 pm
by pickle
Then it's pretty much exactly as easy as adding a listener to the button:
Code: Select all
$("select the links").on('click',function(){
//do stuff here
//return false if you want don't want the link to be followed
});
Re: click handler on a link
Posted: Wed Jun 13, 2012 4:50 pm
by Live24x7
so if write something like this
[text]$("
http://localhost/sytest/usr/register.php").on('click',function(){
alert("Registrations Closed for this month");
});[/text]
and include it in header along with the jQuery source , and then every time i click on a link pointing to the above URL, it should give this alert ?
Is that correct ? or am i missing something ?
It is not working that way so i assume i am missing something.
Thanks for your replies.
Re: click handler on a link
Posted: Wed Jun 13, 2012 4:58 pm
by pickle
You're missing something. You need to have a proper selector:
http://api.jquery.com/category/selectors/
In this case, the selector could be something like:
[syntax]a[href$="register.php"][/syntax]
Re: click handler on a link
Posted: Wed Jun 13, 2012 6:57 pm
by Live24x7
thanks for that selector link.
still not working but i guess will have to do some more reading before getting my hands dirty with the actual code