Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linking use 'id'

Status
Not open for further replies.

officemanager2

Technical User
Oct 11, 2007
116
CA
Can anyone direct me to a good site to understand how to use 'id' with javascript? Like my previous post I am still trying to autofill the body of an email with specific table data from a page. I know this can be done using <a href> but then I would have to repeat the entire paragraph within the <a href> which is fine if it were only one, but on multiple pages with multiple sections this will really slow things down.
 
The use of ID is pretty easy... it's an attribute that gives a unique identifier to any element.

For example:

Code:
<p id="myPara1">Some text</p>
<p id="myPara2">Some more text</p>

The above code would assign the first paragraph an ID of "myPara1" and the second paragraph one of "myPara2".

What can you do with these IDs? Well... you can apply styling to them, using CSS and the hash symbol:

Code:
#myPara1 {
   color: red;
}

#myPara2 {
   color: blue;
}

Or, you can use "document.getElementById" to retrieve a pointer to the element, with which you can do numerous things. This example shows how to display the content of the Ps:

Code:
alert(document.getElementById('myPara1').innerHTML);
alert(document.getElementById('myPara2').innerHTML);

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top