I have a question regarding HTML element selection using javascript.
Here is my code:
Javascript
<script>
function changeText() {
document.getElementsByClassName("CentralContainer")[0].getElementsByClassName("PlayFlowSelect")[0].childNodes[1].innerHTML = "Custom Stream";
}
</script>
HTML
<div class="CentralContainer">
<div class = "PlayFlowSelect">
<input type="image" src="./Home Page Resources/ArrowLeftIcon.png" onclick="changeText()">
<h2> Top Stories </h2>
<input type="image" src="./Home Page Resources/ArrowRightIcon.png" onclick="alert('Trigger Upload Page')">
</div>
For some reason my selection path in my javascript isn't selecting the h2 innerHTML. I'm not sure why... Any help?
nodeTypeof the node retrieved<h2>tag, your code will not work properly. Something like @atmd's answer looks better to me.querySelectorAllwould be better still, as you could just usedocument.querySelectorAll('.CentralContainer .PlayFlowSelect h2')