Note that there are some explanatory texts on larger screens.

plurals
  1. POIf statement with background colors
    primarykey
    data
    text
    <p>Okay, I've been trying to get this for almost 4 hours now, and it just won't work.</p> <p>I have a link:</p> <pre><code>&lt;a id="togglecolor" href="#" onclick="ToggleCover();"&gt; Click here to toggle DIV so you can see what I did. &lt;/a&gt; </code></pre> <p>And I have a div: </p> <pre><code>&lt;div id="framecover" style="position:absolute; width:97%; height:500px; z-index:100; background-color: transparent;"&gt; &lt;/div&gt; </code></pre> <p>I am trying to make a script so the link toggles the background color of the div from transparent to red and back again when you click it again.</p> <p>This is the code I have:</p> <pre><code>$(function() { $('#framecover').css('backgroundColor', "transparent") var framecover = '#framecover' $("a#togglecolor").click(function(){ if ($(framecover).css('backgroundColor') == "transparent") { $(framecover).animate({ backgroundColor: "red" }, "slow"); } else { $(framecover).animate({ backgroundColor: "transparent" }, "slow"); } }); }); </code></pre> <p>Through my testing, I've been able to narrow down to where the problem is. It's on this line: <code>if ($(framecover).css('backgroundColor') == "transparent")</code></p> <p>Undoubtedly, he problem is above code is the wrong syntax for "if framecover's background-color is transparent". The problem is that I have no clue what the syntax is and I've been scouring the internet for two hours looking for the answer and I can't find it.</p> <p><strong>Note:</strong> I do have the jquery color plugin. This code: <code>$(framecover).animate({ backgroundColor: "red" }, "slow");</code> works fine. It's the if statement that's giving me trouble.</p>
    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