Note that there are some explanatory texts on larger screens.

plurals
  1. POCompound if statement is being ignored in JQuery (Javascript)
    primarykey
    data
    text
    <p>I am totally stumped on this. I am putting together a script that checks if two stylesheets are loaded into the head part of a WordPress theme, then load an internal stylesheet only if both external stylesheets are loaded first. But, the final if statement that checks if both external stylesheets "exist" runs as if there is no if statement wrapped around it. In the code, I mention the website where I got this idea from. Below is my code:</p> <pre><code>jQuery(document).ready(function() { /* Place smaller widget design behind .widgettitle only on 3-column layout */ /* adapted from http://churchm.ag/dynamically-applying-stylesheets-using-jquery/ */ //templateDir is defined in functions.php and placed into this theme's head tag var threeColExists = false; // check for blue stylesheet with 3-column stylesheets var blueExists = false; jQuery('link').each(function() { if(jQuery(this).attr('href') === templateDir + '/layouts/3-column-right.css' || templateDir + '/layouts/3-column-left.css' || templateDir + '/layouts/3-column-right-magazine.css' || templateDir + '/layouts/3-column-left-magazine.css') { threeColExists = true; } if(jQuery(this).attr('href') === templateDir + '/styles/blue.css') { blueExists = true; } }); // This is what is getting executed regardless of whether the two conditions below evaluate to true if((threeColExists === true) &amp;&amp; (blueExists === true)) { jQuery('head').append('&lt;style type="text/css"&gt; .widgettitle { background: url(' + templateDir + '/images/widget-design-smaller-blue.png) bottom left no-repeat #FFFFFF; } &lt;/style&gt;'); } }); </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.
    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