Did you know that there is a simpler syntax when it comes to assigning styles for elements in Javascript?

By [)ia6l0 iii

Use SetAttribute to set attributes to an Element

Instead of setting the properties like:

ele.style.position = 'relative';
ele.style.top = '10px';
ele.style.left = '25px';

You can set all in one line: and thereby also avoid the number of actions that the browser has to take on the element.

ele.setAttribute('style','position:relative;top:10px;left:25px;');

Did you know that there is a simpler syntax when it comes to assigning styles for elements in Javascript?  (623 Views)