1

Here is my code for generate combobox. How can I add a css class name 'chosen-select' on it ?

var cell3 = row.insertCell(2);    
var element2 = document.createElement("select");   

var option1 = document.createElement("option");   
option1.value="";   
option1.innerHTML="--Select--";      
element2.appendChild(option1);   

var option2 = document.createElement("option");   
option2.value="1";   
option2.innerHTML="Apple";     
element2.appendChild(option2);   

element2.name = "description" + rowno;  
element2.id = "description" + rowno;   
element2.setAttribute("required","true");   
element2.style.width = "150px";   
cell3.appendChild(element2);   
OlivierH
  • 3,875
  • 1
  • 19
  • 32
Neel
  • 31
  • 1
  • 1
  • 2

1 Answers1

6

You can use className property :

element2.className = "chosen-select";

Documentation

OlivierH
  • 3,875
  • 1
  • 19
  • 32
  • 1
    thanx for your reply but its not working.... – Neel Dec 04 '13 at 09:03
  • It is. You must have mistaken somewhere. Where did you put this line ? – OlivierH Dec 04 '13 at 09:08
  • element2.name = "description" + rowno; element2.id = "description" + rowno; element2.setAttribute("required","true"); element2.style.width = "150px"; element2.className = "chosen-select"; cell3.appendChild(element2); – Neel Dec 04 '13 at 09:59
  • i am using that line on above code pls check it is right??? – Neel Dec 04 '13 at 10:01
  • Works fine for me : http://jsfiddle.net/wmubg/. Have you checked for javascript errors ? – OlivierH Dec 04 '13 at 10:22
  • Actually i am using a template css and js with my code, if you can send your mail id, i will send you that file. – Neel Dec 04 '13 at 10:42
  • No thanks. IF we do it this way, how future visitors on this topic will find the answer they need ? You should close this topic (ie. mark an answer as accepted) an open a new question with your non-working code, since this not really related to class attribute modification anymore. – OlivierH Dec 04 '13 at 10:44
  • Its working with normal css file properly, i drop that css code on jsfiddle.net/wmubg. thanks to help. – Neel Dec 04 '13 at 10:57
  • I have one css file and four js file that have included on my code. how can i send my js and css file to you. – Neel Dec 04 '13 at 11:35
  • Post another question with the code and the problem. This question has already been answered. – OlivierH Dec 04 '13 at 12:38