Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
 
How to Create A Nested Filter:
view plaincopy to clipboardprint?
//a filter allows you to reduce the set of matched elements01.//to those that match a given selector. In this case the query02.//removes anything which doesn't (:not) have (:has) a child with03.//class "selected" (.selected) 04. 05..filter(":not(:has(.selected))")06.
1.
How to Reuse Your Element Searches
view plaincopy to clipboardprint?
varallItems= $("div.item");01. varkeepList= $("div#container1 div.item");02.  03.//Now you can keep working with those jQuery objects. For example,04.//trim down the "keep list" based on checkboxes whose names05.//correspond to
<div>
class names:06. 07.$(formToLookAt + " input:checked").each(function() {08. keepListkeepList= keepList.filter("." + $(this).attr("name"));09. });10.
</div>
 11.
2.
How To Check If An Element contains a certain class orelement with
has()
:
view plaincopy to clipboardprint?
//jQuery 1.4.* includes support for the has method. This method will find01.//if a an element contains a certain other element class or whatever it is02.//you are looking for and do anything you want to them. 03. 04.$("input").has(".email").addClass("email_icon");05.
3.
How to Switch StyleSheets With jQuery:
4.
 
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.
 
view plaincopy to clipboardprint?
$("ul > li").click(
function
() {01. 
var
index = $(
this
).prevAll().length;02.});03.
How to Bind a function to an event:
view plaincopy to clipboardprint?
$('#foo').bind('click',
function
() {01.alert('User clicked on "foo."');02. });03.
11.
How to Append or add HTML to an element:
view plaincopy to clipboardprint?
$('#lal').append('sometext');01.
12.
How to use an object literal to define properties whencreating an element
view plaincopy to clipboardprint?
var
e = $("<a>", { href:"#",
class
:"a‐class another‐class", title:"..."});01. </a>02.
13.
How to Filter using multiple-attributes
view plaincopy to clipboardprint?
<a>01. //This precision‐based approached can be useful when you use 02.  //lots of similar input elements which have different types 03.  
var
elements = $('#someid input[type=sometype][value=somevalue]').get();04. </a>05.
14.
How to Preload images with jQuery:
view plaincopy to clipboardprint?
<a>01.jQuery.preloadImages =
function
() {
for
(
var
i = 0; i').attr('src', arguments[i]); } }; 02.  03.// Usage $.preloadImages('image1.gif', '/path/to/image2.png', 'some/image3.jpg');04. </a>05.
15.
How to set an event handler for any element thatmatches a selector:
16.
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more