Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

How to Accessing Elements using javascript?

4 like 0 dislike
Hello

How to Accessing Elements using javascript?

Please give me your feedback........
asked 1 year ago by rad_joshep (19,390 points)
<a href="http://www.discountu99boots.com/ugg-bailey-button-c-12">ugg bailey button</a>
<a href="http://www.discountu99boots.com/ugg-tall-metallic-c-7">ugg tall metallic</a>
<a href="http://www.discountu99boots.com/ugg-knightsbridge-c-19">ugg knightsbridge</a>
<a href="http://www.discountu99boots.com/ugg-rainier-c-22">ugg rainier</a>
<a href="http://www.discountu99boots.com/ugg-mayfaire-c-20">ugg mayfaire</a>This was truely an amazing trip for me, I’m going to upload my own record of the flight
1 year ago by anonymous

1 Answer

2 like 0 dislike
 
Best answer
To do something interesting with HTML elements, we must first be able to uniquely identify which element we want. In the example
<body>
<form action="">
<input type="button" id="useless" name="mybutton" value="doNothing" />
</form>
</body>

We can use the "getElementById" method (which is generally preferred)
document.getElementById("useless").style.color = "red";
or we can use the older hierarchical navigation method,
document.forms[0].mybutton.style.color = "blue";
Notice that this uses the "name" attribute of the element to locate it.
# Example of Accessing Elements in a DOM.

<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>
answered 1 year ago by daneim (127,080 points)

Related questions

10 like 0 dislike
2 answers
5 like 0 dislike
1 answer
4 like 0 dislike
1 answer
14 like 0 dislike
1 answer
asked 2 years ago by biswaskeran (70,430 points)