Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems getting a simple jquery 'hover' to work
    primarykey
    data
    text
    <p>I have a container <code>&lt;div&gt;</code> into which I dynamically insert third-party content over which I have NO control, in other words, I get what I'm given. </p> <p>If the inserted element on the third-party website had a hover state I have already stored that hover color as a hex color; I can't store it as a style, as this color variable is updated dynamically.</p> <p>What I want to be able to do is apply that hover color variable to the element that's landed inside my container.</p> <p>I can make it work if I code the style in advance, but, as I said, I don't know it in advance so I can't do so. This simple code does work, giving the link an orange hover state. (See my <a href="http://jsfiddle.net/vVjg4/1/" rel="nofollow">working fiddle</a>.):</p> <pre><code>&lt;style&gt; .hovering, #container a:hover {color: orange;} &lt;/style&gt; &lt;script&gt; $('#container').hover(function() { $(this).addClass('hovering'); }, function() { $(this).removeClass('hovering'); }); &lt;/script&gt; &lt;div id="container"&gt; &lt;a href="something"&gt; some link &lt;/a&gt; &lt;/div&gt; </code></pre> <p>However, I have to use the stored hover color variable <code>hoverClass</code> and apply it, but I can't get it to work. I tried this but it's not working. (See <a href="http://jsfiddle.net/cKpLk/1/" rel="nofollow">the fiddle I'm trying to make work</a>.):</p> <pre><code>&lt;script&gt; var hoverClass = '.hovering, #container a:hover {color: orange;}'; $('#container').hover(function() { $(this).addClass(hoverClass); }, function() { $(this).removeClass(hoverClass); }); &lt;/script&gt; &lt;div id="container"&gt; &lt;a href="something"&gt; some link &lt;/a&gt; &lt;/div&gt; </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. 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