How can I add “href” attribute to a link dynamically using JavaScript?

前端 未结 5 1223
不思量自难忘°
不思量自难忘° 2020-11-27 14:43

How can I add the href attribute to a link dynamically using JavaScript?

I basically want to add a href attribute to

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 14:54

    document.getElementById('link-id').href = "new-href";
    

    I know this is an old post, but here's a one-liner that might be more suitable for some folks.

提交回复
热议问题