Attributes of an Element

DOM gives us the facility to change the attribute value of an elemet or to set a new value . We can also remove the attribute value of a div. Silly point to be noted is that attributes are not nodes. They are not even children of any element. So, in order to access its value we first track the element and then obtain its value by getAttribute method.

We will consider this example to explain everything :-
 <iframe id='trackMe'  align='center' width='400' height='200'></iframe>

Suppose, we want to know the width of this iframe. We can do it by :-

	document.getElementById('trackMe').getAttribute('width'); 
	This will return 400
	
Lets try to change its value to another say, 350 :-
document.getElementById('trackMe').setAttribute('width','350');
 It sets its value to 350
	

We can also remove a particular attribute of the element by :-

document.getElementById('trackMe').removeAttribute('width')
The code removes the width attribute of the iframe and set it to the default value of the window.

Lets proceed to append new elements in our document :-

Member Login

Member Login




Not a Member? Sign Up!




Login to comment

Be the first to comment on this topic







  


<<< Wanna review

Continue >>>