Is there a way to add some kind of listener for a type of html element? For example if i wanna call a function when the user clicks any p element
I assume that you are looking for code along these lines:
var paras = document.getElementsByTagName("p"); // Loop through elements. for(var i = 0; i < paras.length; i++) { // Add listener. paras[i].addEventListener("click", function() { // Execute function. }, false); }