niche Posted August 19, 2012 Author Share Posted August 19, 2012 (edited) Please confirm this says, "if the element by id isn't found create it" } else { if ( sTargetID.addEventListener ) { //for better browsers Edited August 19, 2012 by niche Link to comment Share on other sites More sharing options...
dsonesuk Posted August 19, 2012 Share Posted August 19, 2012 (edited) No! If argument 'sTargetID' sent with function registerEvent( sTargetID, sEventName, fnHandler ) is not a id reference var oTarget = document.getElementById( sTargetID ); if ( oTarget != null ) if no element with id sent with sTargetID, as in it EQUALS NULL as example hereregisterEvent( 'popup-link', 'mouseover', show ) which would reference id of <a id="popup-link">Click me to show/hide, or hover to toggle</a> it must be reference to element which an event was triggered else { if ( sTargetID.addEventListener ) { sTargetID.addEventListener( sEventName, fnHandler, true ); } else { var sOnEvent = "on" + sEventName; if ( sTargetID.attachEvent ) { sTargetID.attachEvent( sOnEvent, fnHandler ); } } } that used <div onmouseover="coordinates(event)" id="div1" style="float:left;height:200px;width:500px;margin:0px 0px 10px 0px;background:aqua;"></div> OR <div onmouseover="coordinates(this)" id="div1" style="float:left;height:200px;width:500px;margin:0px 0px 10px 0px;background:aqua;"></div> Edited August 19, 2012 by dsonesuk Link to comment Share on other sites More sharing options...
niche Posted August 19, 2012 Author Share Posted August 19, 2012 (edited) OK. I should should've said in #26, "if the element by id isn't found addEventListener() to sTargetID". Correct? Edited August 19, 2012 by niche Link to comment Share on other sites More sharing options...
dsonesuk Posted August 19, 2012 Share Posted August 19, 2012 Yes! but depending on browser use addEventListener() OR sTargetID.attachEvent. Link to comment Share on other sites More sharing options...
niche Posted August 21, 2012 Author Share Posted August 21, 2012 In post #25 dsonesuk said: but now, should accept a calling of function targeting the current element using 'this' or 'event' as wellonmouseover="coordinates(this)"onmouseover="coordinates(event)" Is that because "this" is always implied? if not, why? Link to comment Share on other sites More sharing options...
dsonesuk Posted August 21, 2012 Share Posted August 21, 2012 when 'this' and 'event' is used as in this case, referes to the current element that triggered the function call, and the event type that was triggered by this current element function call. Link to comment Share on other sites More sharing options...
niche Posted August 21, 2012 Author Share Posted August 21, 2012 (edited) Dsonesuk, please confirm that's because "event" is the argument in coordinates() and that "this" a substitute for event in this example. If "abc" was used the the argument for coordinates() "abc" and "this" could be used interchangeably. Right? Edited August 21, 2012 by niche Link to comment Share on other sites More sharing options...
dsonesuk Posted August 21, 2012 Share Posted August 21, 2012 ??? I don't know what you want, I confirm YES you can use THIS if you want to identify the element that called the function <div onmouseover="coordinates(this)"></div> function coordinates(elem) //elem referes to argument this that referes to element that the function was called from{//with it you can identiy id ref. and for instance a img and its alt attribute alert(elem.id)alert(elem.alt)you can even go through hiearchy and target its parent elem.parentNode, sibling etc} EVENT will refer to to the current elements EVENT ('onmouseover') that called the function. Link to comment Share on other sites More sharing options...
niche Posted August 21, 2012 Author Share Posted August 21, 2012 Your last post helped a lot and zeros in on the variety of info that's sometimes passed through a JS argument. Until recently, I had no idea data movement was so verbose in JS. Thanks for all your help on this topic dsonesuk. As usual you went above and beyond. Thanks also to jsg, thescientist, ShawdowMage and birbal for your help on this topic. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now