I am trying to get the the first element with a specific class which follow the element clicked with pure JS (no JQuery) in the following way but get el.nextSibling is not a fun
nextElement
is a property, not a function, so you don't use ()
with it. That said, using nextSibling
can give you white space content which you don't want. Instead you can use nextElementSibling:
el.nextElementSibling.style.display = 'block';
const togglers = document.querySelectorAll('.toggler');
//console.log(togglers);
togglers.forEach(function(el) {
el.addEventListener('click', function(e) {
//const content = el.innerHTML;
//console.log(content);
el.nextElementSibling.style.display = 'block';
})
});
Click me 1
Click me 2