Navigation
Poll
Would you be an active poster if Ron's Guide had a message board?


Total Votes: 62
Comments: 18 — View
Past pollsPoll idea?
Rate Ron's Guide
Rate our resource at Bigwebmaster.com
Using getElementById()
This brief tutorial will show you how to grab an element in your document with the getElementById() method.

The getElementById() method accepts one parameter, this being an id. "getElementById()" is used to return a reference to an element where the element id attribute matches the value in the parameter.

<div id="mydiv"></div>

<script type="text/javascript">
<!--

var divObj = document.getElementById("mydiv");

//-->
</script>

In the above example, we have a div element that has an id attribute "mydiv". To grab the div element, we use the DOM method "getElementById()" and pass the div id "mydiv" as the parameter.

var divObj = document.getElementById("mydiv");

Now, the variable "divObj" is a reference to the div element. You aren't just limited to div elements, any element that can have an id can be used.

If you have an old javascript book sitting on your desk, it may not explain DOM methods like "getElementById()", it may explain things like "document.all.ID" (Internet Explorer), or "document.ID" (Netscape), but it is common now days to use "getElementById()".

Discuss Tutorial: Using getElementById() 1 Comment
Comment by Mohanganji on Jul 11, 2006, 4:17 pm
i want to become a good java script code developer . i please guide me. when i send request please responde me

thanking you

Yours

Mohan

« Previous [ 1 ] Next »
Post a comment
Sorry, you must be a registered member to post comments.

If you would like to register, you can do so here.
If you already have an account, please login.