0

Possible Duplicate:
Change an element’s CSS class with JavaScript

How can I change the class of <input type="submit:> not using the id, just the class in Javascript. I have have tried this (with no luck):

function changeClass(){
    document.getElementById("wpsc_buy_button").setAttribute("class", "btn btn-success");
}
Community
  • 1
  • 1
  • 3
    This is a dup of a classic: http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript – Ray Toal Dec 11 '12 at 19:15
  • Not exactly a dup (at least the attempt is different), but a similar question, and the answer can be found there. – GolezTrol Dec 11 '12 at 19:17
  • What if i dont want it done on an onclick event and not using any id's, the php generates the id's that why i just wanna concentrate on the class of – MalachNikoff Dec 11 '12 at 19:18
  • You are using the id in the JS shown ... `document.getElementById("wpsc_buy_button")` What do you mean by `How can I change the class of – wirey00 Dec 11 '12 at 19:21
  • Sorry im a bit of a noob, can i use getElementByClassName instead, maybe that will work? – MalachNikoff Dec 11 '12 at 19:35

1 Answers1

0

$('.originalClass').addClass('newClass')

Why would this not work?

you can also do

$('.originalClass').addClass('newClass').removeClass('originalClass');

Leon
  • 542
  • 1
  • 6
  • 15