Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>1 jQuery Object to rule them all</h2> <p>Since you use <code>$("#testApp");</code> at the top of the function you could set it as a variable</p> <pre><code>var testAppEl = $("#testApp") </code></pre> <p>Then use that instead of creating a new jQuery object everytime</p> <h2>Use <code>hover</code></h2> <p>You could put this block:</p> <pre><code>// add a jQuery mouseover and mouseout event $("#testApp").on("mouseover", function() { $("#testApp").on("mouseout", function() { </code></pre> <p>Into a <code>.hover()</code>:</p> <pre><code>testAppEl.hover(function() { $(this).css({ "background-image":"url(./images/svg/menucorner-bg-lit.svg)" }); }, function() { $("#testApp div").css({ "background-image":"url(./images/svg/menucorner-bg.svg)" }); }); </code></pre> <h2>Combine <code>off()</code></h2> <p>These two right here can be mixed</p> <pre><code>// Old $("#testApp").off("mouseover"); $("#testApp").off("mouseout"); // New testAppEl.off("mouseover mouseout"); </code></pre> <h2>Use CSS in a better way</h2> <p>As Drew suggested, add classes in a CSS file instead of dynamic, hard to track CSS through jQuery i.e.:</p> <pre><code>.someCSS { background-image: url(./images/svg/menucorner-bg-lit.svg); height: 200px; background-color:#ccc; } </code></pre> <p>Then in your jQuery use</p> <pre><code>testAppEl.addClass("someCSS"); </code></pre> <h2>Strict Type/Value Comparison</h2> <p>Also, for your first <code>if</code> block, you should really be using the strict comparison operator:</p> <pre><code>if (status === 0) { </code></pre>
 

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