Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Follow the rules</strong><br/> This is a superb example of why we must always code according to the documentation, and not according to the possibilities. Hacks, or mere oversights like this, will eventually be weeded out.</p> <p>The proper jQuery (plain css is better) way to do this follows:</p> <pre class="lang-js prettyprint-override"><code>$("#something a").hover( function() { // $(this).addClass("hovered"); $(this).css("color", "red"); }, function() { // $(this).removeClass("hovered"); $(this).css("color", "black"); } ); </code></pre> <p>The <a href="http://api.jquery.com/hover/" rel="nofollow noreferrer"><code>$.fn.hover</code> method</a> takes up to two arguments and serves as syntactic sugar for more explicit pointer (mouse) events. In fact, the hover method in jQuery 2.1.0 was nothing but this:</p> <pre class="lang-js prettyprint-override"><code>function( fnOver, fnOut ) { return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); } </code></pre> <p><strong>Understand your code, and be concise</strong><br/> As you can see, the <code>fnOver</code> function is called when you enter the element, and again when you exit (if no other method is provided). With this understanding, we can setup simpler instructions:</p> <pre class="lang-js prettyprint-override"><code>$("#something a").hover(function () { $(this).toggleClass("hovered"); }); </code></pre> <p><strong>Native almost always wins</strong><br/> Ultimately, vanilla CSS is the way to go. The <code>:hover</code> pseudo-class has been <a href="http://www.w3.org/TR/CSS2/selector.html#dynamic-pseudo-classes" rel="nofollow noreferrer">around for a long time</a>, and works with targeting not only the element to which it belongs, but nested elements as well:</p> <pre class="lang-css prettyprint-override"><code>#something a:hover { background: red; } #something a:hover .icon { animation: 2s rotate ease-out; } </code></pre> <p>With something as broadly-supported as <code>:hover</code>, I can think of no good reason to avoid it.</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.
    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