Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How to Accessing HTML Elements using javascript?
How to Accessing HTML Elements using javascript?
✍: Guest
To do something interesting with HTML elements, we must first be able to uniquely identify which element we want.
In the example below:
<body>
<form action="">
<input type="button" id="useless" name="mybutton" value="doNothing" />
</form>
</body>
We can use the "getElementById" method using the "id" attribute to identify the element (which is generally preferred)
document.getElementById("useless").style.color = "red";
or we can use the "name" attribute to identify the element:
document.forms[0].mybutton.style.color = "blue";
Here is another example of accessing elements with the DOM object:
<script type="text/javascript" >
function showStatus() {
var selectWidget = document.forms.beerForm.elements["beer"];
var myValue = selectWidget.options[selectWidget.selectedIndex].value;
alert('You drank a \"'+ myValue +"\"");
return true;
}
</script>
<form name="beerForm" action="">
<select name="beer">
<option selected="selected">Select Beer</option>
<option>Heineken</option>
<option>Amstel Light</option>
<option>Corona</option>
<option>Corona Light</option>
<option>Tecate</option>
</select>
<input type="button" name="submitbutton" value="Drink"
onclick="showStatus()" />
</form>
2010-11-23, 4337👍, 0💬
Popular Posts:
.NET INTERVIEW QUESTIONS - Is versioning applicable to private assemblies? Versioning concept is onl...
WHat will be the result of the following code? #define TRUE 0 // some code while (TRUE) { // some co...
What does XmlValidatingReader class do? XmlTextReader class does not validate the contents of an XML...
What will be printed as the result of the operation below: main() { int x=5; printf("%d,%d,%d\n",x,x. ..
What exactly happens when ASPX page is requested from Browser? Note: - Here the interviewer is expec...