view plaincopy to clipboardprint?
//Look for the media‐type you wish to switch then set the href to your new style sheet 01.$('link[media='screen']').attr('href','Alternative.css');02.
How to Limit the Scope of Selection (ForOptimization):
view plaincopy to clipboardprint?
//Where possible, pre‐fix your class names with a tag name01.//so that jQuery doesn't have to spend more time searching 02.//for the element you're after. Also remember that anything 03.//you can do to be more specific about where the element is 04.//on your page will cut down on execution/search times 05. 06.
var
in_stock = $('#shopping_cart_items input.is_in_stock');07.
view plaincopy to clipboardprint?
<ul
id="shopping_cart_items"
>
01.
<li><input
class="is_in_stock" name="item" value="Item‐X" type="radio"
>
Item X
</li>
02.
<li><input
class="3‐5_days" name="item" value="Item‐Y" type="radio"
>
Item Y
</li>
03.
<li><input
class="unknown" name="item" value="Item‐Z" type="radio"
>
Item Z
</li>
04.
</ul>
05. 06.
5.
How to Correctly Use ToggleClass:
view plaincopy to clipboardprint?
//Toggle class allows you to add or remove a class 01.//from an element depending on the presence of that 02.//class. Where some developers would use: 03. 04.a.hasClass('blueButton') ? a.removeClass('blueButton') : a.addClass('blueButton');05.
06.//toggleClass allows you to easily do this using 07. 08.a.toggleClass('blueButton');09.
6.
How to set an IE Specific Function:
view plaincopy to clipboardprint?
if
($.browser.msie) {// Internet Explorer is a sadist. } 01.
7.
How to Replace an element with jQuery:
view plaincopy to clipboardprint?
$('#thatdiv').replaceWith('fnuh');01.
8.
How to Verify if an element is empty:
view plaincopy to clipboardprint?
if
($('#keks').html()) {//Nothing found ;}01.
9.
How to find out the index of an element in anunordered set
10.