Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery hover - add class to current (active) div element, not others
    primarykey
    data
    text
    <p>I'm currently working on a jQuery effect for a button on a website I'm developing and have run into a small issue that I can't figure out how to fix. I have written a short jQuery script to add a class to a div within the button element. It adds a hover class to an arrow next to the text for the link and removes it when you mouse out – pretty simple. However, if you look at this example (<a href="http://steadfastdesignfirm.com/rgw/experience/" rel="nofollow">Example</a>) you'll notice that when you hover over the first button, all the arrows in the following buttons are also activated, because it adds the css class to every element on the page with that class identifier.</p> <p><a href="http://steadfa.st/7I2S" rel="nofollow">Click here</a> to view a screenshot of the problem.</p> <p>How do I make the script add the class to only the current arrow in the div and not all the others on the page? Here's my html, css and jQuery:</p> <p><strong>HTML</strong></p> <pre><code>&lt;div class="end-lft"&gt;&lt;/div&gt; &lt;a href="&lt;?php echo BASE_URL; ?&gt;doctors/" class="btn"&gt;Visit our Doctors page&lt;/a&gt; &lt;div class="end-rght-h"&gt;&lt;/div&gt;&lt;!-- This is the element that has a hover class applied when a user hovers over a.btn above --&gt; </code></pre> <p><strong>CSS</strong></p> <pre><code>.end-lft { background: url('images/ui/page/btn-lft.jpg') no-repeat 0 0; width: 4px; height: 33px; display: block; float: left; clear: left; } a.btn { background: url('images/ui/page/btn-bg.jpg') repeat-x 0 0; width: auto; height: 33px; padding: 6px 7px 0 7px; display: block; float: left; font-size: 0.9em; text-decoration: none !important; } .end-rght-h { background: url('images/ui/page/btn-arrw-h.jpg') no-repeat 0 0; width: 22px; height: 33px; display: block; float: left; clear: right; } .end-rght-v { background: url('images/ui/page/btn-arrw-v.jpg') no-repeat 0 0; width: 22px; height: 33px; display: block; float: left; clear: right; } </code></pre> <p><strong>jQuery</strong></p> <pre><code>$(document).ready(function() { $(".btn").hover(function() { $('.end-rght-h, .end-rght-v').addClass("hvr"); }, function() { $('.end-rght-h, .end-rght-v').removeClass("hvr"); }); }); </code></pre>
    singulars
    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.
    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