Reputation: 43778
Does anyone know how to detect the clicked href URL in JQuery? For example I have the following links, some is redirect to the new page and some will call to the javascript to expand the div. How can I use the JQuery/Javascript to detect the href if no ID been use.
<a href="www.test.com">Test 1</a>
<a href="javascript:test()">Test 2</a>
<a href="www.test2.com">Test 3</a>
<a href="www.test3.com">Test 4</a>
<a href="javascript:test2()">Test 5</a>
Upvotes: 3
Views: 6054
Reputation: 22339
Does anyone know how to detect the clicked href URL in JQuery?
$("a").click(function(event){
// Capture the href from the selected link...
var link = this.href;
alert(link);
// do something if required....
// would prevent the link from executing, if that is something you want to do...
return false; // not needed if you want the link to execute normally...
});
Upvotes: 7