Re: [jQuery] how to get href value
$(document).ready(function() { $(a).click(function(event) { alert( You clicked a link to + this.href ); return false; }); }); This method is very slow. Try using event delegation: $(document).ready(function() { $(document).click(function(event){ if ($(event.target).is('a') { alert( You clicked a link to + event.target.href); return false; } }); }); -- Andrei Eftimie http://eftimie.com +40 758 833 281 Punct http://designpunct.ro
[jQuery] how to get href value
I'm trying to get href value from anchor tag. code $(document).ready(function() { $(a).click(function(event) { alert(As you can see, the link no longer took you to jquery.com); //$(a).html.href; event.preventDefault(); }); }); a href=http://jquery.com/;jQuery/a /code
Re: [jQuery] how to get href value
$(a).attr(href);
Re: [jQuery] how to get href value
But that would give you the href for the first A element in the document, not necessarily the one you clicked. Going back to the OP's code, this.href would be the easiest way to get it: $(document).ready(function() { $(a).click(function(event) { alert( You clicked http://jquery.com/a link to + this.href ); return false; }); }); -Mike On Tue, Jan 19, 2010 at 9:14 PM, Matt Quackenbush quackfu...@gmail.comwrote: $(a).attr(href);
Re: [jQuery] how to get href value
Got it ..., thanks all On Wed, Jan 20, 2010 at 1:22 PM, Michael Geary m...@mg.to wrote: But that would give you the href for the first A element in the document, not necessarily the one you clicked. Going back to the OP's code, this.href would be the easiest way to get it: $(document).ready(function() { $(a).click(function(event) { alert( You clicked http://jquery.com/a link to + this.href ); return false; }); }); -Mike On Tue, Jan 19, 2010 at 9:14 PM, Matt Quackenbush quackfu...@gmail.comwrote: $(a).attr(href); -- Adi Gunanta Sembiring Blog: http://adisembiring.wordpress.com YM: adisembir...@yahoo.com GTalk: adi.sembir...@gmail.com e-mail: sembiring@gmail.com Facebook: sembiring@gmail.com HP: +62 852 6892 4259