<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codrops &#187; snippets</title>
	<atom:link href="http://tympanus.net/codrops/tag/snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://tympanus.net/codrops</link>
	<description>Useful resources and inspiration for creative minds</description>
	<lastBuildDate>Wed, 23 May 2012 09:46:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Some Useful JavaScript &amp; jQuery Snippets &#8211; Part 4</title>
		<link>http://tympanus.net/codrops/2010/01/11/some-useful-javascript-jquery-snippets-part-4/</link>
		<comments>http://tympanus.net/codrops/2010/01/11/some-useful-javascript-jquery-snippets-part-4/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 10:43:10 +0000</pubDate>
		<dc:creator>cody</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=1199</guid>
		<description><![CDATA[How to get client ip address with jQuery $.getJSON("http://jsonip.appspot.com?callback=?",function(data){ alert( "Your ip: " + data.ip); }); How to parse XML with jQuery file.xml: &#60;?xml version="1.0" ?&#62; &#60;result&#62; &#60;item&#62; &#60;id&#62;1&#60;/id&#62; &#60;title&#62;title1&#60;/title&#62; &#60;description&#62;desc1&#60;/description&#62; &#60;/item&#62; &#60;item&#62; &#60;id&#62;2&#60;/id&#62; &#60;title&#62;title2&#60;/title&#62; &#60;description&#62;desc2&#60;/description&#62; &#60;/item&#62; &#60;!-- ... --&#62; &#60;/result&#62; $.get('file.xml',{},function(data){ $('item',data).each(function(){ var $this       = $(this); var id             = $this.find('id').text(); var [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1210" title="snippets4" src="http://tympanus.net/codrops/wp-content/uploads/2010/01/snippets4.png" alt="snippets4" width="500" height="380" /></p>
<li><strong>How to get client ip address with jQuery</strong></li>
<pre class="brush:js">$.getJSON("http://jsonip.appspot.com?callback=?",function(data){
    alert( "Your ip: " + data.ip);
});</pre>
<li><strong>How to parse XML with jQuery</strong></li>
<p>file.xml:</p>
<pre class="brush:xml">&lt;?xml version="1.0" ?&gt;
&lt;result&gt;
    &lt;item&gt;
        &lt;id&gt;1&lt;/id&gt;
        &lt;title&gt;title1&lt;/title&gt;
        &lt;description&gt;desc1&lt;/description&gt;
    &lt;/item&gt;
    &lt;item&gt;
        &lt;id&gt;2&lt;/id&gt;
        &lt;title&gt;title2&lt;/title&gt;
        &lt;description&gt;desc2&lt;/description&gt;
    &lt;/item&gt;
    &lt;!-- ... --&gt;
&lt;/result&gt;</pre>
<pre class="brush:js">$.get('file.xml',{},function(data){
    $('item',data).each(function(){
        var $this       = $(this);
        var id             = $this.find('id').text();
        var title         = $this.find('title').text();
        var description = $this.find('description').text();
        //do something ...
    });
});</pre>
<div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div>
<li><strong>How to get the number in the ids</strong></li>
<pre class="brush:xml">&lt;div id="sites"&gt;
    &lt;a id="site_1" href="http://siteA.com"&gt;siteA&lt;/a&gt;
    &lt;a id="site_2" href="http://siteB.com"&gt;siteB&lt;/a&gt;
    &lt;a id="site_3" href="http://siteB.com"&gt;siteC&lt;/a&gt;
    ...
&lt;/div&gt;</pre>
<p>you need to get 1 from site_1, 2 from site_2 &#8230;</p>
<pre class="brush:js">$("#sites a").click(function(){
    var $this     = $(this);
    var nmb     = $this.attr('id').match(/site_(\d+)/)[1];
    ...
});</pre>
<li><strong>How to transform a number like 12343778 into 12.343.778</strong></li>
<pre class="brush:xml">&lt;div id="result"&gt;12343778&lt;/div&gt;</pre>
<pre class="brush:js">var delimiter = '.';
$('#result').html()
            .toString()
            .replace(new RegExp("(^\\d{"+($this.html().toString().length%3||-1)+"})(?=\\d{3})"),"$1" + delimiter)
            .replace(/(\d{3})(?=\d)/g,"$1" + delimiter);</pre>
<li><strong>Count number of textarea lines</strong></li>
<pre class="brush:js">var text = $("#textareaId").val();
var lines = text.split(/\r|\r\n|\n/);
alert(lines.length);</pre>
<li><strong>Logging to the firebug console</strong></li>
<pre class="brush:js">jQuery.fn.log = function (msg) {
    console.log("%s: %o", msg, this);
    return this;
};
$('#some_div').find('li.source &gt; input:checkbox').log("sources to uncheck").removeAttr("checked");</pre>
<li><strong>Find X/Y of an HTML element with Javascript</strong></li>
<pre class="brush:js">// Based on: http://www.quirksmode.org/js/findpos.html
var getCumulativeOffset = function (obj) {
    var left, top;
    left = top = 0;
    if (obj.offsetParent) {
        do {
            left += obj.offsetLeft;
            top  += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return {
        x : left,
        y : top
    };
};</pre>
<li><strong>Validate Credit Card</strong></li>
<pre class="brush:js">function isCreditCard( CC ){
    if (CC.length &gt; 19)
        return (false);

    sum = 0; mul = 1; l = CC.length;
    for (i = 0; i &lt; l; i++){
        digit = CC.substring(l-i-1,l-i);
        tproduct = parseInt(digit ,10)*mul;
        if (tproduct &gt;= 10)
            sum += (tproduct % 10) + 1;
        else
            sum += tproduct;
        if (mul == 1)
            mul++;
        else
            mul–;
    }
    if ((sum % 10) == 0)
        return (true);
    else
        return (false);
}</pre>
<li><strong>Distinguish left and right mouse click</strong></li>
<pre class="brush:js">$("#element").live('click', function(e) {
    if( (!$.browser.msie &amp;&amp; e.button == 0) || ($.browser.msie &amp;&amp; e.button == 1) ) {
        alert("Left Button");
    }
    else if(e.button == 2)
        alert("Right Button");
});</pre>
<li><strong>How to get the native image size</strong></li>
<pre class="brush:js">var img = $('#imageid');
var theImage = new Image();
theImage.src = img.attr("src");
alert("Width: " + theImage.width);
alert("Height: " + theImage.height);</pre>
<p><!-- wp_ad_camp_1 --></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2010/01/11/some-useful-javascript-jquery-snippets-part-4/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Some Useful JavaScript &amp; jQuery Snippets &#8211; Part 3</title>
		<link>http://tympanus.net/codrops/2010/01/08/some-useful-javascript-jquery-snippets-part-3/</link>
		<comments>http://tympanus.net/codrops/2010/01/08/some-useful-javascript-jquery-snippets-part-3/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 13:16:01 +0000</pubDate>
		<dc:creator>cody</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=1162</guid>
		<description><![CDATA[How to hide all children div except a specific one with jQuery? $('#target div:not(#exclude)').hide(); //or $('#target').children().filter(':not(#exclude)').hide(); Detecting when a div’s height changes using jQuery $('element').bind('resize', function(){ alert( 'Height changed to' + $(this).height() ); } Delete all table rows except first $('someTableSelector').find('tr:gt(0)').remove(); Selecting root element of a certain level in the document 1 level: $('*:not(* *)'); [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1177" title="snippets_part3" src="http://tympanus.net/codrops/wp-content/uploads/2010/01/snippets_part3.png" alt="snippets_part3" width="500" height="380" /></p>
<li><strong>How to hide all children div except a specific one with jQuery?</strong></li>
<pre class="brush:js">$('#target div:not(#exclude)').hide();
//or
$('#target').children().filter(':not(#exclude)').hide();</pre>
<li><strong>Detecting when a div’s height changes using jQuery</strong></li>
<pre class="brush:js">$('element').bind('resize', function(){
alert( 'Height changed to' + $(this).height() );
}</pre>
<li><strong>Delete all table rows except first</strong></li>
<pre class="brush:js">$('someTableSelector').find('tr:gt(0)').remove();</pre>
<li><strong>Selecting root element of a certain level in the document</strong></li>
<pre class="brush:js">1 level:
$('*:not(* *)');
2 level:
$('*:not(* *)').find('&gt; *');
3 level:
$('*:not(* *)').find('&gt; * &gt; *');</pre>
<div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div>
<li><strong>Searching a string in jQuery</strong></li>
<pre class="brush:js">var foundin = $('*:contains("some string bla bla")');</pre>
<li><strong>Get the distance scrolled from top</strong></li>
<pre class="brush:js">alert($(document).scrollTop());</pre>
<li><strong>Select all elements except the ones with a given class</strong></li>
<pre class="brush:js">$('* :not(.someclass)')</pre>
<li><strong>Add a row to a table</strong></li>
<pre class="brush:js">$('#myTable tr:last').after('&lt;tr&gt;...&lt;/tr&gt;');</pre>
<li><strong>How to convert decimal to hexadecimal?</strong></li>
<pre class="brush:js">num = num.toString(16);
reverse process:
num = parseInt(num, 16);</pre>
<li><strong>Filtering By More Than One Attribute in JQuery</strong></li>
<pre class="brush:js">var elements = $('#someid input[type=sometype][value=somevalue]').get();</pre>
<li><strong>How to expire a cookie in x minutes</strong></li>
<pre class="brush:js">var date = new Date();
date.setTime(date.getTime() + (x * 60 * 1000));
$.cookie('example', 'foo', { expires: date });</pre>
<li><strong>Selecting the first x items with jQuery</strong></li>
<pre class="brush:js">example: first 10 anchors
$('a').slice(0,10);
//or
$('a:lt(10)');</pre>
<li><strong>Working with a select element</strong></li>
<pre class="brush:js">//Get the value of a selected option
$('selectElement').val();

//Get the text of a selected option
$('#selectElementId :selected').text();

//Remove an option (e.g. id=1)
$("#selectElementId option[value='1']").remove();</pre>
<p><!-- wp_ad_camp_1 --></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2010/01/08/some-useful-javascript-jquery-snippets-part-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Some Useful JavaScript &amp; jQuery Snippets &#8211; Part 2</title>
		<link>http://tympanus.net/codrops/2010/01/07/some-useful-javascript-jquery-snippets-part-2/</link>
		<comments>http://tympanus.net/codrops/2010/01/07/some-useful-javascript-jquery-snippets-part-2/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 17:05:15 +0000</pubDate>
		<dc:creator>cody</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=1147</guid>
		<description><![CDATA[Check if cookies are enabled $(document).ready(function() { var dt = new Date(); dt.setSeconds(dt.getSeconds() + 60); document.cookie = "cookietest=1; expires=" + dt.toGMTString(); var cookiesEnabled = document.cookie.indexOf("cookietest=") != -1; if(!cookiesEnabled){ //cookies are not enabled } }); Toggle all checkboxes var tog = false; // or true if they are checked on load $('a').click(function() { $("input[type=checkbox]").attr("checked",!tog); tog = [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1152" title="snippets_part2" src="http://tympanus.net/codrops/wp-content/uploads/2010/01/snippets_part2.png" alt="snippets_part2" width="500" height="380" /></p>
<li><strong>Check if cookies are enabled</strong></li>
<pre class="brush:js">$(document).ready(function() {
    var dt = new Date();
    dt.setSeconds(dt.getSeconds() + 60);
    document.cookie = "cookietest=1; expires=" + dt.toGMTString();
    var cookiesEnabled = document.cookie.indexOf("cookietest=") != -1;
    if(!cookiesEnabled){
        //cookies are not enabled
    }
});</pre>
<li><strong>Toggle all checkboxes</strong></li>
<pre class="brush:js">var tog = false; // or true if they are checked on load
$('a').click(function() {
    $("input[type=checkbox]").attr("checked",!tog);
    tog = !tog;
});</pre>
<li><strong>Get the index of an element</strong></li>
<pre class="brush:js">$("ul &gt; li").click(function () {
    var index = $(this).prevAll().length;
});</pre>
<li><strong>Validate date of birth</strong></li>
<pre class="brush:js">$("#lda-form").submit(function(){
    var day = $("#day").val();
    var month = $("#month").val();
    var year = $("#year").val();
    var age = 18;
    var mydate = new Date();
    mydate.setFullYear(year, month-1, day);

    var currdate = new Date();
    currdate.setFullYear(currdate.getFullYear() - age);
    if ((currdate - mydate) &lt; 0){
        alert("Sorry, only persons over the age of " + age + " may enter this site");
        return false;
    }
    return true;
});</pre>
<div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div>
<li><strong>Test if an element is visible</strong></li>
<pre class="brush:js">if($(element).is(":visible")) {
    //The element is Visible
}</pre>
<li><strong>Counting child elements</strong></li>
<pre class="brush:js">&lt;div id="foo"&gt;
&lt;div id="bar"&gt;&lt;/div&gt;
&lt;div id="baz"&gt;
&lt;div id="biz"&gt;
&lt;/div&gt;
&lt;span&gt;&lt;span&gt;
&lt;/div&gt;

//jQuery code to count child elements
$("#foo &gt; div").length</pre>
<li><strong>Center an element on the screen</strong></li>
<pre class="brush:js">jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

//Use the above function as:
$(element).center();</pre>
<li><strong>Moving options from list A to list B</strong></li>
<pre class="brush:js">$().ready(function() {
    $('#add').click(function() {
        !$('#select1 option:selected').appendTo('#select2');
    });
    $('#remove').click(function() {
        !$('#select2 option:selected').appendTo('#select1');
    });
});</pre>
<li><strong>Select all checkboxes</strong></li>
<pre class="brush:js">$(document).ready(function(){
    $("#checkboxall").change(function(){
        var checked_status = this.checked;
        $("input[name=checkall]").attr("checked", checked_status);
    });

});</pre>
<li><strong>Get the current URL</strong></li>
<pre class="brush:js">$(document).ready(function() {
    var pathname = window.location.pathname;
});</pre>
<li><strong>Check if and which key was pressed</strong></li>
<pre class="brush:js">$(function() {
    $(document).keypress(function(e){
        switch(e.which){
        // "ENTER"
        case 13:
        alert('enter pressed');
        break;

        // "s"
        case 115:
        alert('s pressed');
        break;

        (...)

        }
    });

});</pre>
<p><!-- wp_ad_camp_1 --></p>
<div class="partner_section_post"><span>Message from Testking</span>We are among the best  <a href="http://www.pass4sure.com/CCIE-Service-Provider.html">ccie service provider</a>  to help you better prepare  for <a href="http://www.pass4sure.com/CCNA.html">ccna exam</a>. Sign up for online prep course to successfully pass <a href="http://www.pass4sure.com/CCIE-Wireless.html">ccie wireless</a>  certification.</div>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2010/01/07/some-useful-javascript-jquery-snippets-part-2/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Some Useful JavaScript &amp; jQuery Snippets</title>
		<link>http://tympanus.net/codrops/2010/01/05/some-useful-javascript-jquery-snippets/</link>
		<comments>http://tympanus.net/codrops/2010/01/05/some-useful-javascript-jquery-snippets/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 15:36:01 +0000</pubDate>
		<dc:creator>cody</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=1110</guid>
		<description><![CDATA[How to refresh the src of an image with jQuery? $(imageobj).attr('src', $(imageobj) .attr('src') + '?' + Math.random() ); How to see if an image is loaded or not with jquery var imgsrc = 'img/image1.png'; $('&#60;img/&#62;').load(function () { alert('image loaded'); }).error(function () { alert('error loading image'); }).attr('src', imgsrc); And if a set (example : 10 images) [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1132" title="snippets" src="http://tympanus.net/codrops/wp-content/uploads/2010/01/snippets.png" alt="snippets" width="500" height="380" /></p>
<li><strong>How to refresh the src of an image with jQuery?</strong></li>
<pre class="brush:js">$(imageobj).attr('src', $(imageobj)
           .attr('src') + '?' + Math.random() );</pre>
<li><strong>How to see if an image is loaded or not with jquery</strong></li>
<pre class="brush:js">var imgsrc = 'img/image1.png';
$('&lt;img/&gt;').load(function () {
    alert('image loaded');
}).error(function () {
    alert('error loading image');
}).attr('src', imgsrc);</pre>
<li><strong>And if a set (example : 10 images) of images are loaded</strong></li>
<pre class="brush:js">var totalimages  = 10;
var loadedimages = 0;
$("&lt;img/&gt;").load(function() {
    ++loadedimages;
    if(loadedimages == totalimages){
        //All 10 images are loaded
    }
});</pre>
<li><strong>How to remove selected text after mouse double click event</strong></li>
<pre class="brush:js">clearSelection      : function () {
    if(document.selection &amp;&amp; document.selection.empty) {
        document.selection.empty();
    } else if(window.getSelection) {
        var sel = window.getSelection();
        sel.removeAllRanges();
    }
}
$(element).bind('dblclick',function(event){
    //do something
    clearSelection();
});</pre>
<div id="bsap_1266918" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div>
<li><strong>Validate email address:</strong></li>
<pre class="brush:js">var email = 'info@tympanus.net'
if(!(/^((([a-z]|\d|[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email)))
alert('Invalid Email');</pre>
<li><strong>How to order a &lt;ul&gt; element using jQuery</strong></li>
<pre class="brush:js">&lt;ul&gt;
&lt;li&gt;cloud&lt;/li&gt;
&lt;li&gt;sun&lt;/li&gt;
&lt;li&gt;rain&lt;/li&gt;
&lt;li&gt;snow&lt;/li&gt;
&lt;/ul

var items = $('.to_order li').get();
items.sort(function(a,b){
    var keyA = $(a).text();
    var keyB = $(b).text();

    if (keyA &lt; keyB) return -1;
    if (keyA &gt; keyB) return 1;
    return 0;
});
var ul = $('.to_order');
$.each(items, function(i, li){
    ul.append(li);
});</pre>
<li><strong>Passing parameters to a function called with setTimeout</strong></li>
<pre class="brush:js">timeout = setTimeout(function(){myFunction(param)},time);</pre>
<li><strong>Disable right mouse click</strong></li>
<pre class="brush:js">$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});</pre>
<li><strong>Fade out an image, and fade in another one (replacing the previous one)</strong></li>
<pre class="brush:js">$('imageelement').fadeOut(function() {
    $(this).load(function() {
        $(this).fadeIn();
    }).attr('src', AnotherSource);
});</pre>
<li><strong>Write your own selectors</strong></li>
<pre class="brush:js">//extend the jQuery functionality
$.extend($.expr[':'], {

    //name of your special selector
    moreThanAThousand : function (a){
        //Matching element
        return parseInt($(a).html()) &gt; 1000;
    }
});

$(document).ready(function() {
    $('td:moreThanAThousand').css('background-color', '#ff0000');
});</pre>
<li><strong>Run a function 5 times with intervals of 20 seconds</strong></li>
<pre class="brush:js">var count = 0;
function myFunction() {
    count++;
    if(count &gt; 5) clearInterval(timeout);
    //do something
}
var timeout = setInterval(myFunction, 20000);</pre>
<li><strong>Check if an element exists</strong></li>
<pre class="brush:js">if ($("#elementid").length) {
    //it does!
}</pre>
<li><strong>Cancel an ajax request</strong></li>
<pre class="brush:js">var req = $.ajax({
type:     "POST",
url:     "someurl",
data:     "id=1",
success: function(){
//something
}
});
//Cancel the Ajax Request
req.abort()</pre>
<p><!-- wp_ad_camp_1 --></p>
<div class="partner_section_post"><span>Message from Testking</span>If want to learn how  to use javascript and JQuery to create powerful websites then join <a href="http://www.testkingsite.com/microsoft/70-647.html">testking 70-647</a> online designing course and get expert <a href="http://www.testkingsite.com/cisco/350-018.html">testking 350-018</a> reviews and  and <a href="http://www.testkingsite.com/cisco/640-553.html">testking 640-553</a> tutorials to  learn how to create effective web lauouts.</div>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2010/01/05/some-useful-javascript-jquery-snippets/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  tympanus.net/codrops/tag/snippets/feed/ ) in 0.24493 seconds, on May 24th, 2012 at 12:59 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 24th, 2012 at 1:59 am UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  tympanus.net/codrops/tag/snippets/feed/ ) in 0.00022 seconds, on May 24th, 2012 at 1:06 am UTC. -->
