To do this, it is necessary to render our code so that it listens for the event that is going to be triggered. You have to use the method onClick. You can extract the pressed element from the event.
< form>Execution:
Enter a name< br />
< input id="text" />
< input type="button" value="Validate" />
< h3 id="res">
< script>
document.onclick= function(event) {
// the event is used to detect which component the click went to
if (event===undefined) event= window.event;
var target= 'target' in event? event.target: event.srcElement;
document.getElementById("res").innerHTML = "I clicked on an element of type "+target.tagName;
};
A click outside of the web page such as the back button and in some browsers cannot be detected for security reasons.
Commentaires (0)
Laisser un commentaire
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Chargement des commentaires...