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

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

Assuming that the html contains the following structure:



         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 12:34

    Put an id on it, e.g.

    ...
       ^^^^^^^^^^^^^^
    

    then the JS is simply

    document.getElementById('the_a_tag').href = 'new address goes here';
    

    as long as you put the javascript AFTER the relevant HTML.

    And note: CSS is for presentation only. With a few exceptions, it cannot affect the content of document elements, merely how they appear (color/size/position/etc...).

提交回复
热议问题