javascript - Why is the id not changing? -



javascript - Why is the id not changing? -

i'm trying alter colour of text. alter id on div tag ,using javascrip,t different css rules apply.

home.html

<html> <head> <link rel="stylesheet" type="text/css" href="style-original.css" /> <meta charset="utf-8" /> <title>test</title> <script type="text/javascript"> <!-- function change() { document.getelementbyid("part1").classname = "part2" } //--> </script> </head> <body> hello.<br /> <div id="part1">test test.</div><br /> <input type='button' onclick='change()' value='form checker' /> </body> </html>

style-original.css

#part1 { color: #ff0000; } #part2 { color: #7d26cd; }

the colour doesn't alter when button clicked. problem? problem is changing classname should changing id. big fat "doh" moment.

the minimal amount of work work alter change() function this:

document.getelementbyid("part1").id = "part2"

you'd need maintain track of current id though, or change() function not find element again.

javascript html css getelementbyid

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -