You can use this
as a parameter to add the element the handler is attached to. You can then use this parameter in the handler function. event.target
will refer to the clicked element which propagates to the lijst
element, not the element the handler is attached to. querySelector()
will return the first matched element.
function test(el) {
console.log(el.querySelector('p').textContent);
}
<li class="lijst" onclick="test(this)">
<p>Naam, PraktijkNaam</p>
<p>Adres</p>
<p>Email</p>
<p>Mobiel</p>
</li>
Better would be to get rid of the inline event handler and define the event handler in javascript as in snippet below.
document.querySelectorAll('.lijst').forEach(el => {
el.addEventListener('click', function(){
console.log(this.querySelector('p').textContent);
});
});
<li class="lijst">
<p>Naam, PraktijkNaam</p>
<p>Adres</p>
<p>Email</p>
<p>Mobiel</p>
</li>
<li class="lijst">
<p>Naam, Nog een PraktijkNaam</p>
<p>Adres</p>
<p>Email</p>
<p>Mobiel</p>
</li>