TheFundamentals Posted September 11, 2014 Share Posted September 11, 2014 Hi, on page 292, Larry says that the target property 'points to the HTML element that triggered the event'. Does this mean that, in the following example, var target points to the same location as var username: function checkUsername(e) { var target = e.target; } var username = document.getElementById('name'); username.addEventListener('blur', checkUsername, false); If so, is this a general rule i.e. does the target property 'point' to the same location as document methods such as getElementById()? Thanks. Link to comment Share on other sites More sharing options...
HartleySan Posted September 12, 2014 Share Posted September 12, 2014 In that example, yes, target will point to the same DOM object as is assigned to the username variable. However, something important to note is that if you set up an event handler for a DOM element that contains subelements, then that event will fire for any of the subelements as well. For example, if you set up a click event handler for a div that contains p elements, then clicking on any of the p elements will cause the click event for the div to fire, and in that case, target will refer to the p element that was clicked on, not the parent div. That make sense? Link to comment Share on other sites More sharing options...
TheFundamentals Posted September 12, 2014 Author Share Posted September 12, 2014 Hi HartleySan, thanks for the explanation, yeah I think I've got it! Link to comment Share on other sites More sharing options...
Recommended Posts