Rey Rajesh
Rey Rajesh

Reputation: 500

How to give class name to a newly created element?

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?

Upvotes: 0

Views: 115

Answers (1)

mplungjan
mplungjan

Reputation: 177691

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.

Upvotes: 3

Related Questions