Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery - How can I stop appending connect to an element selected by class?
    primarykey
    data
    text
    <p>I have a page that describes various options that people can implemenet. To better define these explanations I have an icon that reveals a large relevant image on hover.</p> <p>The html for this would look something like (for simplicity I have included only 2 elements with class x but in reality there would be a lot more)</p> <pre><code>&lt;div id="innerlayout"&gt; &lt;ul&gt; &lt;li&gt;Content for 1 &lt;a class="x" href="javascript:void(0)" rel="large-image-1.jpg" title="Caption for Large Image 1"&gt; &lt;img src="learn-more.jpg" alt="Learn More Icon" width="30" height="30" /&gt; &lt;/a&gt; &lt;/li&gt; &lt;li&gt;Content for 2 &lt;a class="x" href="javascript:void(0)" rel="large-image-2.jpg" title="Caption for Large Image 2"&gt; &lt;img src="learn-more.jpg" alt="Learn More Icon" width="30" height="30" /&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>The jQuery I currently have looks like this.</p> <pre><code>$document.ready(function() { $('a.x', $('#innerlayout')).hover( function () { var path = $(this).attr('rel'); var text = $(this).attr('title'); $(this).append($("&lt;p class='revealer'&gt;&lt;img src='"+path+"' /&gt;&lt;br /&gt;"+text+"&lt;/p&gt;")); $('p.revealer').hide().fadeIn(500); }, function () { $(this).find('p:last').remove(); } ); }); </code></pre> <p>This works fine but I was looking to change it so that the appended paragraph was hidden rather than removed, the class of the &lt;a&gt; tag changed to something other than "x" and subsequent hovers of this newly classed &lt;a&gt; would show the now existing content. I came up with this, but this continues to append the content on each subsequent hover despite the changed &lt;a&gt; element class. Can anyone suggest to me what I'm doing wrong here, and how I might fix it? Thanks in advance.</p> <pre><code>$(document).ready(function() { $('a.x', $('#innerlayout')).hover( function () { var path = $(this).attr('rel'); var text = $(this).attr('title'); $(this).append($("&lt;p class='revealer'&gt;&lt;img src='"+path+"' /&gt;&lt;br /&gt;"+text+"&lt;/p&gt;")); $('p.revealer').hide().fadeIn(500); }, function () { $(this).find('p:last').hide(); $(this).removeClass('x').addClass('revealed'); } ); $('a.revealed', $('#innerlayout')).hover( function() { $(this).find('p').show(); }, function () { $(this).find('p').hide(); } ); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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