Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't I add an event to each element in a collection that refers to Itself rather than the last element in the "for(){}" statement
    primarykey
    data
    text
    <p>On <code>Window</code>'s load, every <code>DD</code> element inside <code>Quote_App</code> should have an <code>onCLick</code> event appended that triggers the function <code>Lorem</code>, however, <code>Lorem</code> returns the <code>nodeName</code> and <code>Id</code> of the last element in the <code>For</code> statement rather than that of the element that trigged the function. I would want <code>Lorem</code> to return the <code>nodeName</code> and <code>Id</code> of the element that triggered the function.</p> <pre><code>function Lorem(Control){ /* this.Control=Control; */ this.Amet=function(){ return Control.nodeName+"\n"+Control.id; }; }; function Event(Mode,Function,Event,Element,Capture_or_Bubble){ if(Mode.toLowerCase()!="remove"){ if(Element.addEventListener){ if(!Capture_or_Bubble){ Capture_or_Bubble=false; }else{ if(Capture_or_Bubble.toLowerCase()!="true"){ Capture_or_Bubble=false; }else{ Capture_or_Bubble=true; }; }; Element.addEventListener(Event,Function,Capture_or_Bubble); }else{ Element.attachEvent("on"+Event,Function); }; }; }; function Controls(){ var Controls=document.getElementById("Quote_App").getElementsByTagName("dd"); for(var i=0;i&lt;Controls.length;i++){ var Control=Controls[i]; Event("add",function(){ var lorem=new Lorem(Control); lorem.Control=Control; alert(lorem.Amet()); },"click",Controls[i]); }; }; Event("add",Controls,"load",window); </code></pre> <p>Currently you click on any <code>DD</code> element <code>Lorem</code> always returns the <code>nodeName</code> and <code>Id</code> of the last <code>DD</code> element.</p> <p><code>Lorem</code> should return the <code>nodeName</code> and <code>Id</code> of the <code>Control</code> (<code>Control[i]</code>) that triggered <code>Lorem</code>.</p> <p>How do I go about making this happen?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload