Getting an anchor element's absolute URL with jQuery

后端 未结 3 1923
隐瞒了意图╮
隐瞒了意图╮ 2021-02-19 05:12

Given an anchor element (with something like $(\"a:first\")), how do you get the absolute URL that the anchor points to?

3条回答
  •  野的像风
    2021-02-19 05:48

    If you're using jQuery 1.6+, you can use .prop():

    $("a:first").prop("href")
    

    Prior to 1.6, you can access the href property directly on the DOM element:

    $("a:first")[0].href;
    

提交回复
热议问题