DOM: Difference between revisions

35 bytes added ,  8 April 2020
m
Changed from Web Programming to Web Applications category
mNo edit summary
m (Changed from Web Programming to Web Applications category)
 
(One intermediate revision by one other user not shown)
Line 11: Line 11:
Javascript can access elements of a webpage by referring to their ID values.  The following line of HTML is for a link that has an id of "url" and points to "http://www.yahoo.com":
Javascript can access elements of a webpage by referring to their ID values.  The following line of HTML is for a link that has an id of "url" and points to "http://www.yahoo.com":


<pre>
<source lang="html">
<a id="url" href="http://www.yahoo.com">testing</a>
<a id="url" href="http://www.yahoo.com">testing</a>
</pre>
</source>


The following Javascript code will find the Element with an id value of ''url'', and will then set the href attribute of it to "http://www.msdn.com"
The following Javascript code will find the Element with an id value of ''url'', and will then set the href attribute of it to "http://www.msdn.com"
<pre>
<source lang="js">
  // This line fetches and handle to the Element with id ''url'' and returns it to the variable ''link''
  // This line fetches and handle to the Element with id ''url'' and returns it to the variable ''link''
  link=document.getElementById('url');
  link=document.getElementById('url');
  // This line sets the href attribute of the link item to "http://www.msdn.com"
  // This line sets the href attribute of the link item to "http://www.msdn.com"
  link.href="http://www.msdn.com";
  link.href="http://www.msdn.com";
</pre>
</source>


==External Links==
==External Links==
Line 28: Line 28:




[[Category: Web Programming]]
[[Category: Web Applications]]