Jump to content

adding an event to a created element Solved with thanks


niche

Recommended Posts

Please confirm this says, "if the element by id isn't found create it"

} else {		if ( sTargetID.addEventListener ) {  //for better browsers

Edited by niche
Link to comment
Share on other sites

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 by dsonesuk
Link to comment
Share on other sites

OK. I should should've said in #26, "if the element by id isn't found addEventListener() to sTargetID". Correct?

Edited by niche
Link to comment
Share on other sites

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

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 by niche
Link to comment
Share on other sites

??? 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...