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 .
click handler on a link
Moderator: General Moderators
Re: click handler on a link
Using just raw Javascript? jQuery? MooTools?
How are you adding your handler to the button?
How are you adding your handler to the button?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: click handler on a link
sorry - i am still fiddling with all these - but the case in question is jQuery
Re: click handler on a link
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
});Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: click handler on a link
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.
[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
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]
In this case, the selector could be something like:
[syntax]a[href$="register.php"][/syntax]
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: click handler on a link
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
still not working but i guess will have to do some more reading before getting my hands dirty with the actual code