I have a code and I just can't make it work. A target occurs on an element and I have to find it's next sibling or I could go to its parent and then search for the sibling's class using queryselector.
The code works perfect if I replace the ** line ** with a query selector, so the problem is with the sibling method its 100%.
Do you have an idea what am I doing wrong?
/*we put on event listener for each "refsz" class*/
var elements = document.getElementsByClassName("refsz");
for (var z = 0; z < elements.length; z++) {
elements[z].addEventListener('click', callThis, false);
}
/*and when the event occurs, I select the sibling div's innerHTML and change
"success" div's innerHTML to this*/
function callThis() {
**var temp= event.target.nextSibling.innerHTML;**
document.querySelector("#success").innerHTML = temp;
}
<div class="parent">
<div> class="refsz"> I will click this </div>
<div> class="sibling"> I need the innerHTML of this sibling</div>
</div>
<div id="success"></div>