How to detect the clicked href URL in JQueryJavascript - Stack Overflow

Does anyone know how to detect the clicked href URL in JQuery? For example I have the following links,

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742284092a4415013.html

相关推荐

  • How to detect the clicked href URL in JQueryJavascript - Stack Overflow

    Does anyone know how to detect the clicked href URL in JQuery? For example I have the following links,

    23小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信