0

I am creating a new element like this:

var cell3=row.insertCell(2);
var t3=document.createElement("input");
t3.id = "txtEstStartDt"+index;
cell3.appendChild(t3);

As I have given an id to the element, I want to give a class.

t3.class = "abc";

Will this work?

Rey Rajesh
  • 502
  • 1
  • 6
  • 25

1 Answers1

3

You need to use className

t3.className = "abc";

Alternative in jQuery (since you tagged it such) would be

var t3 = $("<input/>",{"id":"txtEstStartDt"+index,"class":"abc"});

or later:

t3.addClass("abc");

but then it would be better to make it all jQuery.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Well, with jQuery alternative version it also should be, for example, `cell3.appendChild(t3[0]);` – Regent Nov 07 '14 at 12:21
  • the whole script would look different in jQuery :) with `$t3.appendTo($cell3) ` or such – mplungjan Nov 07 '14 at 12:23
  • 1
    Yes, or `$(cell3).append(t3);` or many other ways, I just want to mention that jQuery alternative requires others changes in code. – Regent Nov 07 '14 at 12:25