admin管理员组

文章数量:1332395

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">Test 1</a>
<a href="javascript:test()">Test 2</a>
<a href="www.test2">Test 3</a>
<a href="www.test3">Test 4</a>
<a href="javascript:test2()">Test 5</a> 

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.">Test 1</a>
<a href="javascript:test()">Test 2</a>
<a href="www.test2.">Test 3</a>
<a href="www.test3.">Test 4</a>
<a href="javascript:test2()">Test 5</a> 
Share Improve this question edited Sep 17, 2012 at 23:57 Jin Yong asked Sep 17, 2012 at 23:02 Jin YongJin Yong 43.8k72 gold badges144 silver badges194 bronze badges 2
  • 4 What do you mean by detect the href? – Ram Commented Sep 17, 2012 at 23:04
  • 1 I am confused about the 'selected' word. Are you talking about when someone is using the tab key to move through the tabable objects? Or, are you asking to detect which one has been clicked? – demersus Commented Sep 17, 2012 at 23:06
Add a ment  | 

1 Answer 1

Reset to default 7

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...
});

本文标签: How to detect the clicked href URL in JQueryJavascriptStack Overflow