Is that possible to do? Can anyone help me syntaxically express this better?
Asked
Active
Viewed 57 times
-4
-
4We have a search bar up top, to the right – André Snede Jan 24 '14 at 11:03
-
1are you saying the queswtion is dumb or that i expressed it well enough that the search bar should have show it? Because it did not show the answer as I understand the words, but I think I just learned a lot by this code, so I'd like to say tannks and if anyone wants art .gif .apng .jpg i work adobe full creative suite, every program in it (all of the adobe) and corel, even mspaint when i'm problem solving, let me know your graphic design problem i'll solve it in thanks for this answer I got. – Guildenstern Jan 24 '14 at 11:37
1 Answers
0
Your Question is already answered here: Change an element's class with JavaScript
if ( document.getElementById("MyElement").className.match(/(?:^|\s)MyClass(?!\S)/) ){
document.getElementById("MyElement").className = document.getElementById("MyElement").className.replace( /(?:^|\s)MyClass(?!\S)/g , '' ); //Remove Myclass
document.getElementById("MyElement").className += " AnotherClass"; //Add another class
}
-
1@EvilDevil this is not a valid answer. You should have flagged it as duplicate or left a comment on the question. What you are doing here is claiming reputation for an answer that someone else wrote / answered already. – RononDex Jan 24 '14 at 11:36
-
-
I mean why does it post when I push enter to write a new line, that's terrible. OK Here's the bit of code I found that finds elements in JS: document.getElementById("MyElement").className = "MyClass"; I'd like to change this so it instead finds things by CSS class rather than unique CSS id. Is that... even sensical or am I making more nonsense words? – Guildenstern Jan 25 '14 at 01:27