Game Development Reference
In-Depth Information
<script>
// 1. Capture the image element inside that nav
structurewith id="navOptions"
// ----------------------------------
// Without query selectors:
// ----------------------------------
var nav = document.getElementById("navOptions");
var img = null;
// Iterate through every child node of nav
instead ofdirectly targeting the current
// position of that image element in case the
structureof #navOptions change,
// in which case this code wouldn't need to be
updated.
for (var i = 0, len = nav.children.length; i <
len; i++) {
if (nav.children[i].tagName == "IMG") {
img = nav.children[i];
break;
}
}
// -----------------------------------
// With the query selectors:
// -----------------------------------
var img = document.querySelector("#navOptions
img");
// 2. Set the click handler
if (img) {
img.addEventListener("click",
doOnOptionsClicked);
}
</script>
Search WWH ::




Custom Search