Js operating elements of style

1. Elemental .style. Attribute = "attribute value '

var div = document.getElementById ( ' Box ' ) 
div.style.width = ' 300px by ' ; 
div.style.height = ' 300px by ' ; 
div.style.backgroundColor = ' Red ' ;   // CSS has - attributes, js wanted to change in the nomenclature hump

2.div.style. Property Gets elements of style

var div = document.getElementById ( ' Box ' ) 
the console.log (div.style.width); 
the console.log (div.style.height); 
the console.log (div.style.backgroundColor);    // if through style Gets the style, can only get inline style

3. By operating type, change the style element

var div = document.getElementById ( ' Box ' ) 
div.className + = ' One '     // + space must remember

 

Guess you like

Origin www.cnblogs.com/zhaodz/p/11617779.html