Zuber Surya
Zuber Surya

Reputation: 869

DOM element addclass not working in IE7

i am creating div using DOM Element as

phototab = document.createElement('div');
phototab.setAttribute('class', 'phototab fleft');
//phototab.className = "phototab fleft";

i tried both methods but it is not adding class in IE7

Upvotes: 2

Views: 1286

Answers (2)

Pointy
Pointy

Reputation: 413836

You can't use setAttribute() to affect things that are actually properties of DOM elements.

phtototab.className = 'phototab fleft';

should work. (It's an IE thing; other browsers are less picky, but for IE a property is a property and an attribute is an attribute.)

edit — I should say that you shouldn't use .setAttribute() when it's unnecessary.

Upvotes: 3

Derek 朕會功夫
Derek 朕會功夫

Reputation: 94339

How about jQuery?

phototab = $("<div>").addClass("phototab fleft");

That's all! Very simple. :)

Upvotes: -1

Related Questions