getElementByClass().setAttribute doesn't work

前端 未结 2 1475
长情又很酷
长情又很酷 2020-11-29 12:24

why when i write

document.getElementByClass(\'home1\').setAttribute(\'style\', \'background-image:url(img/red_menu.PNG);\');

it doesn\'t wo

2条回答
  •  孤独总比滥情好
    2020-11-29 12:59

    If you have only one classname in your entire HTML file, then you could also use

      document.getElementsByClassName('navbar-nav')[0].setAttribute('id', 'navbar-toggle');

提交回复
热议问题