Add another class to a div with javascript

Posted by zac on Stack Overflow See other posts from Stack Overflow or by zac
Published on 2010-04-29T18:09:04Z Indexed on 2010/04/29 18:17 UTC
Read the original article Hit count: 180

Filed under:

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 the html content. BUt I think would work better for me if I could also add a class to a div as well. So for example I have..

if (under certain age) {
     document.getElementById('hello').innerHTML = "<p>Good Bye</p>"; 
             createCookie('age','not13',0)
    return false;
            }
            else {
                 document.getElementById('hello').innerHTML = "<p>Hello</p>";  
                return true;
            }

What I would like to do is have everything in a div and if return false then that div disappears and is replaced with other content.. can I get any ideas on a good way to achieve this with pure javascript. I dont want to use jQuery for this particular function.

© Stack Overflow or respective owner

Related posts about JavaScript