TheFundamentals 0 Posted September 11, 2014 Report 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. Quote Link to post Share on other sites
HartleySan 826 Posted September 12, 2014 Report 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? Quote Link to post Share on other sites
TheFundamentals 0 Posted September 12, 2014 Author Report Share Posted September 12, 2014 Hi HartleySan, thanks for the explanation, yeah I think I've got it! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.