Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Nothing seems to be wrong with that situation...</p> <p>html:</p> <pre><code>&lt;div class="sub" rel="0"&gt; &lt;img&gt; &lt;/div&gt; &lt;div class="sub" rel="1"&gt; &lt;img&gt; &lt;/div&gt;​ </code></pre> <p>js:</p> <pre><code>console.log($('.sub[rel=0] img')[0]);​ </code></pre> <p>console:</p> <pre><code>&lt;img&gt; </code></pre> <p>jsfiddle: <a href="http://jsfiddle.net/PHrRY/" rel="nofollow">http://jsfiddle.net/PHrRY/</a></p> <p><strong>moreover</strong></p> <p>Here is an example where there is a triggered click event. For you to trigger a click event on that image, it must have an attached event. More than likely if there is no event, nothing happens, and that is why your trigger is not actually firing an event off. This code will fire the event using <code>trigger</code>.</p> <p>jsfiddle: <a href="http://jsfiddle.net/PHrRY/1/" rel="nofollow">http://jsfiddle.net/PHrRY/1/</a></p> <p><strong>edit</strong></p> <p>Here is an example where the <code>0</code> for rel is stored in a variable:</p> <p>summary: <code>var relNumber = "0 0"; console.log($('.sub[rel="'+relNumber+'"] img')[0]);</code></p> <p><a href="http://jsfiddle.net/PHrRY/3/" rel="nofollow">http://jsfiddle.net/PHrRY/3/</a></p> <p>The extra <code>"</code> quotation marks are used in case there is a space inside of the <code>relNumber</code>.</p> <p><strong>In response to update</strong></p> <p>this code should be</p> <pre><code>if(realid){ $('.sub[rel="'+realid+'"] img').trigger('click'); } $('.sub[rel="'+realid+'"] img').click(function(){ console.log('hi'); }); </code></pre>
    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