Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>this</code> changes meaning as you step into new nested functions. It does <strong>not</strong> change meaning when you call <code>$()</code> to create a new element. </p> <p>So immediately inside of</p> <pre><code>$.each(obj, function(index, dataObj) { </code></pre> <p><code>this</code> is the current object over which your looping. Once you get here:</p> <pre><code>.live("click",function(event) { // &lt;------ inside of nested function openVideo($(event.target).data(dataID)); }) </code></pre> <p><code>this</code> is the element on which you clicked. </p> <p>But calling </p> <pre><code> $("&lt;li/&gt;",{data:{dataID:dataObj.id},text:dataObj.name}) </code></pre> <p>to create a new <code>li</code> element does <strong>not</strong> set <code>this</code> to the newly created element. </p> <hr> <p>Also, if you want to save the meaning of <code>this</code> even inside of nested functions, the standard way is to save it to a new variable.</p> <pre><code>$.each(obj, function() { var self = this; </code></pre> <p>Now <code>self</code> can be used instead of <code>this</code> as the item you're currently "on" anywhere in your loop, even in nested function handlers. Or you can pass index and dataObjects to the each function - same effect. </p> <p><strong>EDIT</strong></p> <p>As a comment pointed out, you're using live incorrectly. If you're using jQuery 1.7, you'll want:</p> <pre><code>$(document).on("click", "li", function(event) { openVideo($(this).data(dataID)); }); </code></pre> <p>in your <code>document.ready</code> handler. If all li's that will be clicked will be in a certain div, than select on that div instead of <code>document</code>. If you don't want this click handler to apply to all li's, but only some, then decorate all the li's you want this click handler to apply to with a css class, then instead of passing the filter "li" to <code>on</code>, you'd pass <code>li.yourClass</code> </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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