JavaScript getAttribute Style

This page discusses - JavaScript getAttribute Style

JavaScript getAttribute Style

JavaScript getAttribute Style


We have discussed in our previous examples the use of getAttribute() method. Visit the link to get the example of getAttribute() method. In this example we will describe you the use of getAttribute() method with the "style" attribute.

Explanation with code :

To illustrate this example we have created an html page in which we have created a div with its auto "width" and fixed height. We have created a button also "Change Width" and it calls a user defined function getAttributeStyle() defined in the JavaScript.

function getAttributeStyle() {

In this function we have fetched the div element's reference and with this reference we can further call the getAttribute("style") method to have its "style" attribute. Now we can change <div> width by the specified value.

Full html code of the example is as follows :

     getAttribute Style Example
     <script language="javascript" >
	function getAttributeStyle() {
   <div style="background: #DFDFFF; width:'100%';" align="center">
    <font color="#000080" size="12pt">
	<b>getAttribute Style</b>
 <div id="myDiv" style="background:#ffffdd; height:100px; 
	Welcome to RoseIndia Technologies
	Rose India Technologies Pvt. Ltd.
	is a global services company that
	ensures maximum returns on 
	investments by providing quality 
	software solutions and services 
	to its clients.
     <input type="button" value="Change Width" 

Output :

As you will click on the button "Change Width" it will change the width by the "style" attribute.

Download Source Code