adding classes (serially numbered) to each DIV on page automatically via javascript?

后端 未结 3 1824
庸人自扰
庸人自扰 2021-01-15 03:15

i\'m running a contact-form-plugin on my wordpress installation. everything works fine but i want to style my form a little bit more. to do it like this i have to style some

3条回答
  •  青春惊慌失措
    2021-01-15 03:56

    You could do this:

    var divs = document.getElementsByTagName("div");
    var className = "myClass";
    for( var i = 0, max = divs.length; i< max; i++ ){
     divs[i].setAttribute("class",className + i.toString());
    }
    

提交回复
热议问题