How to change the href for a hyperlink using jQuery

前端 未结 12 2120
孤街浪徒
孤街浪徒 2020-11-21 11:15

How can you change the href for a hyperlink using jQuery?

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 11:52

    With jQuery 1.6 and above you should use:

    $("a").prop("href", "http://www.jakcms.com")
    

    The difference between prop and attr is that attr grabs the HTML attribute whereas prop grabs the DOM property.

    You can find more details in this post: .prop() vs .attr()

提交回复
热议问题