0

I am creating input tag with it's attributes by clicking on list item. Type, name and id are created successfully but it's not generating the class attribute.

var createInput = document.createElement("input");
        createInput.type = "text";
        createInput.name = text1;    
        createInput.id = text1;
        createInput.class = "abc";
mohsin
  • 594
  • 2
  • 8
  • 29
  • `element.setAttribute("atrribute", "value");` Now, let's close this question as a duplicate. – Max Oct 21 '15 at 22:22
  • This might be helpful http://stackoverflow.com/questions/22576927/how-to-dynamically-change-css-class-of-div-tag – JGV Oct 21 '15 at 22:22
  • It's actually `className` as `class` is a reserved word in javascript – adeneo Oct 21 '15 at 22:22

1 Answers1

0

The class property of a DOM Element is actually called className:

createInput.className = "abc";

Check out your browser's Debug Console (F12); it has auto-completion, so you can see what properties exist.

Kenney
  • 9,003
  • 15
  • 21