Find div with certain class.
Information
On this web page find all div with the id "FindMe". When these specific div's are found, display the text.
Text 1.
Text 2.
Code
<div id="FindMe">Text 1.</div>
<div id="FindMe">Text 2.</div>
<script type="text/javascript" language="JavaScript">
function find_div_class() {
var divCollection = document.getElementsByTagName("div");
for (var i=0; i<divCollection.length; i++) {
if(divCollection[i].getAttribute("id") == "FindMe") {
findMeText = divCollection[i].innerHTML;
alert(findMeText);
}
}
}
</script>
Press the button to find the divs with class "FindMe".<br />
<input type="button" onfocus="this.blur()"
value="FindMe" onclick="javascript:find_div_class();return false;""/>
Result
Press the button to find the divs with id "FindMe".
|