Hi aLL, i Wan't to know that what does getElementById Do in js?
we also use that in CrossSiteScripting attacks,
thanks
Hi aLL, i Wan't to know that what does getElementById Do in js?
we also use that in CrossSiteScripting attacks,
thanks
Most html constructs have an element called "id" which must be unique in the whole html page. Such as <div id="uniqueDiv1">. getElementById returns that HTML object. In my example, getElementById("uniqueDiv1") returns that div. You can then use it to set a style or do something with it.
It returns an element from the HTML document that has the ID attribute set to the value you ask for. For example, the JavaScript
document.getElementById('myId');
will return the first element found that matches that ID, such as
<a id="myId">Link</a>
I say the "first element found" because that's exactly what will happen--by definition, IDs must be unique in the page. Each HTML page must have only 1 ID of the same name. If you violate this rule, you'll get unexpected results.
getElementById allows you to access elements of a page.
Lets use this page as an example:
<html>
<head>
<title>Test Page</title>
</head>
<body>
<div id="myDIV">Hello World!</div>
</body>
</html>
document.getElemenById('myDIV').innerHTML will give you Hello World!
document.getElementById('myDIV').style.display = "none" will hide the div tag.
If you want to look at what all it can do on a live page I would suggest getting Firefox and install the Firebug addon. This will let you see all of the DOM things and play with them without having to re-save a page.