javascript - setAttribute is not working for 'style' attribute on IE -


I'm keeping a piece of JS code for Firefox in Internet Explorer. I had to face the problem of changing the style of an element by using setAttribute method which was working on Firefox.

  button. SetUvit ('style', 'float: right;');  

I tried to set the style member of the button and it does not work either. This was the solution for setting the onclic event handler.

  button.style = 'float: right;';  

First of all, I want to know the solution to the problem above and second, there is no maintained list for these differences between browsers?

Because the style itself is an object what you want:

  Button.style.setupviet ('cssFloat', 'right');  

But if IE does not support setAttribute for style object, then use fully cross-browser:

  button.style.cssFloat = ' Right ';  

For reference, I always go to www.quirksmode.org. Specially:. Click on all DOM related goods.

And finally, to set several attributes, I usually use something:

  function setStyle (el, spec) {for (var n fiction In) {el.style [n] = fiction [n]; }}  

Usage:

  set style (button, {cssFloat: 'right', range: '2px solid black'});  

Note: object.attribute = 'value' however works in all browsers, it can not always work for non-HTML DOM objects. For example, if your document contains embedded SVG graphics that you need to manipulate with javascript, then you have to use setAttribute to do this.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -