how can the value of an href attribute be changed using javascript/css?

后端 未结 4 1270
陌清茗
陌清茗 2021-01-29 12:19

Assuming that the html contains the following structure:



         


        
4条回答
  •  轮回少年
    2021-01-29 12:39

    You could do it without id:

    document.querySelector("a[href^='http://the']")
    

    and set the href prop:

    document.querySelector("a[href^='http://the']").href=whatever
    

    For a full reference (browser-compatibility) of querySelector see the MDN-Article

提交回复
热议问题