Note that there are some explanatory texts on larger screens.

plurals
  1. POTarget an parent element but without knowing how many nodes are in between child and parent
    primarykey
    data
    text
    <p>The HTML may be:</p> <pre><code>&lt;div class="SomeWrapper"&gt; &lt;img scr="img2.jpg" /&gt; &lt;img scr="img3.jpg" /&gt; &lt;img scr="img4.jpg" /&gt; &lt;img scr="img5.jpg" /&gt; &lt;/div&gt; </code></pre> <p>or it could be</p> <pre><code>&lt;div class="SomeWrapper"&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;img scr="img1.jpg" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;img scr="img2.jpg" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;img scr="img3.jpg" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;img scr="img4.jpg" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;img scr="img5.jpg" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;/div&gt; </code></pre> <p>my javascript is checking for a loaded image. On image loaded, it wants to apply some effects to the first parent element after "SomeWrapper" div (not the image itself).</p> <p>Normally I would do something like <code>.parent().parent()</code> but I don't always know how many parents the image will have.</p> <pre><code>$obj.find("img").load(function(){ $(this).parent().animate({opacity: '1'},{duration: settings.fadeSpeed}); }); </code></pre> <p>How could I target the correct parent in place of <code>$(this).parent()</code> above?</p> <p><strong>edit</strong>: <code>$obj</code> happens to be the element I want to target</p> <p><strong>edit 1</strong>: I don't know the value of parent class name, in this case ".SomeWrapper" so I can't use $(".SomeWrapper")</p> <p>I could get that value by fetching it from the DOM though, but I would prefer a relative solution that doesn't rely on hardcoded classes or id's</p> <p><strong>edit 2</strong>: Here are the actual files</p> <p><a href="https://github.com/ed-lea/jquery-collagePlus/blob/f4fb3f12750394acdd627fc4d2f2aa3a5091e17d/examples/example-size-in-tag.html" rel="nofollow">https://github.com/ed-lea/jquery-collagePlus/blob/f4fb3f12750394acdd627fc4d2f2aa3a5091e17d/examples/example-size-in-tag.html</a></p> <p>Here I want to replace <code>.parent().parent()</code> as it's a dynamic value <a href="https://github.com/ed-lea/jquery-collagePlus/blob/f4fb3f12750394acdd627fc4d2f2aa3a5091e17d/jquery.collagePlus.js#L316" rel="nofollow">https://github.com/ed-lea/jquery-collagePlus/blob/f4fb3f12750394acdd627fc4d2f2aa3a5091e17d/jquery.collagePlus.js#L316</a></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