Add another class to a div

前端 未结 7 943
盖世英雄少女心
盖世英雄少女心 2020-11-29 07:29

I have a function that checks the age of a form submission and then returns new content in a div depending on their age. Right now I am just using getElementById to replace

7条回答
  •  清酒与你
    2020-11-29 07:39

    Well you just need to use document.getElementById('hello').setAttribute('class', 'someclass');.

    Also innerHTML can lead to unexpected results! Consider the following;

    var myParag = document.createElement('p');
    
    if(under certain age)
    {
        myParag.text="Good Bye";
        createCookie('age', 'not13', 0);
        return false;
    {
    else
    {
        myParag.text="Hello";
        return true;
    }
    
    document.getElementById('hello').appendChild(myParag);
    

提交回复
热议问题