开发者

element.setAttibute() method how to make it work in I.E?

I am setting the style attribute of a text via js element.setAttribute() method with name=style and value="my modifications to the style of text"

it is working well in brows开发者_如何学Pythoners other than IE ..

In order to make it possible ,what should i do ?

for your information i m modifying these attributes -- text-align,text-decoration,font-style,font-weight,font-size....

I will be happy if someone guides me thank you..


Another way for IE which "preserve" the ordinary syntax of CSS is cssText property:

element.style.cssText = "text-align: center; text-decoration: underline; font-size: 120%;";

Official documentation: http://msdn.microsoft.com/en-us/library/ms533698(v=vs.85).aspx


Just avoid setAttribute. It does nothing that can't be done though other methods.

element.style.textAlign = 'left';

for example.

That said, you are almost certainly better off predefining your styles and then causing them to be applied with:

element.className += 'someClass';

… or a library that implements addClass and removeClass methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜