<?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>CSS-TricksCSS-Tricks</title>
	<atom:link href="http://css-tricks.com/jquery-snippets-feed/" rel="self" type="application/rss+xml" />
	<link>http://css-tricks.com</link>
	<description>Tips, Tricks, and Techniques on using Cascading Style Sheets.</description>
	<lastBuildDate>Fri, 24 May 2013 13:07:49 +0000</lastBuildDate>
	<language></language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>

	<generator>http://wordpress.org/?v=3.5.1</generator>

	
		<item>
			<title>Mover Cursor to End of Textarea</title>
			<link>http://css-tricks.com/snippets/jquery/mover-cursor-to-end-of-textarea/</link>
			<comments>http://css-tricks.com/snippets/jquery/mover-cursor-to-end-of-textarea/#comments</comments>
			<pubDate>Sat, 20 Apr 2013 17:47:14 +0000</pubDate>
			<dc:creator>Chris Coyier</dc:creator>
				<guid isPermaLink="false">http://css-tricks.com/?page_id=21353</guid>

			<description><![CDATA[<p>Setting the value of a textarea moves the cursor to the end. So you just need to save the value, clear it, focus it, and re-apply the value and you're good. </p>
<code class="language-javascript">$("button").on("click", function() {
  
  // cache textarea as we need it more than once
  var textarea = $("textarea"),
      
      // save old value as we need to clear it
      val = textarea.val();
  
  // focus textarea, clear value, re-apply
  textarea
    .focus()
    .val("")
    .val(val);
});</code>
<p>This demo does that but also applies a &#8230;</p>]]></description>

			<content:encoded><![CDATA[<p>Setting the value of a textarea moves the cursor to the end. So you just need to save the value, clear it, focus it, and re-apply the value and you're good. </p>
<pre rel="jQuery"><code class="language-javascript">$("button").on("click", function() {
  
  // cache textarea as we need it more than once
  var textarea = $("textarea"),
      
      // save old value as we need to clear it
      val = textarea.val();
  
  // focus textarea, clear value, re-apply
  textarea
    .focus()
    .val("")
    .val(val);
});</code></pre>
<p>This demo does that but also applies a little bit of UX. If the textarea's current value doesn't end in a space, add one. Just so you can click-and-keep-typing as you might.</p>
<pre class="codepen" data-height="200" data-type="result" data-href="gBdLE" data-user="chriscoyier" data-safe="true"><code></code><a href="http://codepen.io/chriscoyier/pen/gBdLE">Check out this Pen!</a></pre>
<p>You could make it a plugin as well:</p>
<pre rel="jQuery"><code class="language-javascript">$.fn.focusToEnd = function() {
   return this.each(function() {
       var v = $(this).val();
       $(this).focus().val("").val(v);
   });
};</code></pre>
]]></content:encoded>

			<wfw:commentRss>http://css-tricks.com/snippets/jquery/mover-cursor-to-end-of-textarea/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>

						
		</item>

	
		<item>
			<title>Track Window Resizes through Google Analytics</title>
			<link>http://css-tricks.com/snippets/jquery/track-window-resizes-through-google-analytics/</link>
			<comments>http://css-tricks.com/snippets/jquery/track-window-resizes-through-google-analytics/#comments</comments>
			<pubDate>Wed, 03 Apr 2013 17:24:09 +0000</pubDate>
			<dc:creator>Chris Coyier</dc:creator>
				<guid isPermaLink="false">http://css-tricks.com/?page_id=21004</guid>

			<description><![CDATA[<p>Sparkbox <a href="http://seesparkbox.com/foundry/google_analytics_and_the_resize_event">has this snippet</a> to help figure out how often browser windows really are resized.</p>
<code class="language-javascript">(function() {
  var resizeTimer;
  
  // Assuming we have jQuery present
  $( window ).on( "resize", function() {
    
    // Use resizeTimer to throttle the resize handler
    clearTimeout( resizeTimer );
    resizeTimer = setTimeout(function() {

     /* Send the event to Google Analytics
      *
      * https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEventTracking
      * _trackEvent(category, action, opt_label, opt_value, opt_noninteraction)   
      */
      var $window = $( window );
      _gaq.push( [ "_trackEvent", "User Actions", "Browser Resize", $window.width() + " x &#8230;</code>]]></description>

			<content:encoded><![CDATA[<p>Sparkbox <a href="http://seesparkbox.com/foundry/google_analytics_and_the_resize_event">has this snippet</a> to help figure out how often browser windows really are resized.</p>
<pre rel="jQuery"><code class="language-javascript">(function() {
  var resizeTimer;
  
  // Assuming we have jQuery present
  $( window ).on( "resize", function() {
    
    // Use resizeTimer to throttle the resize handler
    clearTimeout( resizeTimer );
    resizeTimer = setTimeout(function() {

     /* Send the event to Google Analytics
      *
      * https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEventTracking
      * _trackEvent(category, action, opt_label, opt_value, opt_noninteraction)   
      */
      var $window = $( window );
      _gaq.push( [ "_trackEvent", "User Actions", "Browser Resize", $window.width() + " x " + $window.height() ] );
    }, 1000);
  });
})();</code></pre>
<p>Note how easy it is to track events in Google Analytics. That can be used for just about anything.</p>
]]></content:encoded>

			<wfw:commentRss>http://css-tricks.com/snippets/jquery/track-window-resizes-through-google-analytics/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>

						
		</item>

	
		<item>
			<title>Clear a File Input</title>
			<link>http://css-tricks.com/snippets/jquery/clear-a-file-input/</link>
			<comments>http://css-tricks.com/snippets/jquery/clear-a-file-input/#comments</comments>
			<pubDate>Wed, 16 Jan 2013 21:20:28 +0000</pubDate>
			<dc:creator>Chris Coyier</dc:creator>
				<guid isPermaLink="false">http://css-tricks.com/?page_id=19886</guid>

			<description><![CDATA[<p>You can just clone it and replace it with itself, with all events still attached.</p>
<p></p>
<code class="language-javascript">var input = $("#control");

function something_happens() {
    input.replaceWith(input.val('').clone(true));
};&#8230;</code>]]></description>

			<content:encoded><![CDATA[<p>You can just clone it and replace it with itself, with all events still attached.</p>
<p><input type="file" id="control"></p>
<pre rel="jQuery"><code class="language-javascript">var input = $("#control");

function something_happens() {
    input.replaceWith(input.val('').clone(true));
};</code></pre>
<pre class="codepen" data-height="150" data-type="result" data-href="obzdG" data-user="chriscoyier" data-safe="true"></pre>
]]></content:encoded>

			<wfw:commentRss>http://css-tricks.com/snippets/jquery/clear-a-file-input/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>

						
		</item>

	
		<item>
			<title>Draggable without jQuery UI</title>
			<link>http://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/</link>
			<comments>http://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/#comments</comments>
			<pubDate>Fri, 27 Jul 2012 17:38:46 +0000</pubDate>
			<dc:creator>Chris Coyier</dc:creator>
				<guid isPermaLink="false">http://css-tricks.com/?page_id=17603</guid>

			<description><![CDATA[<p>It doesn't have all the fancy callbacks and options, but hey, it makes things draggable (and with a specified handle optionally). </p>
<code>(function($) {
    $.fn.drags = function(opt) {

        opt = $.extend({handle:"",cursor:"move"}, opt);

        if(opt.handle === "") {
            var $el = this;
        } else {
            var $el = this.find(opt.handle);
        }

        return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
            if(opt.handle === "") {
                var $drag = $(this).addClass('draggable');
            } else {
                var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
            }
            var z_idx = $drag.css('z-index'),
                drg_h = $drag.outerHeight(),
                drg_w = $drag.outerWidth(),
                pos_y = &#8230;</code>]]></description>

			<content:encoded><![CDATA[<p>It doesn't have all the fancy callbacks and options, but hey, it makes things draggable (and with a specified handle optionally). </p>
<pre rel="jQuery" class="lang-js"><code>(function($) {
    $.fn.drags = function(opt) {

        opt = $.extend({handle:"",cursor:"move"}, opt);

        if(opt.handle === "") {
            var $el = this;
        } else {
            var $el = this.find(opt.handle);
        }

        return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
            if(opt.handle === "") {
                var $drag = $(this).addClass('draggable');
            } else {
                var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
            }
            var z_idx = $drag.css('z-index'),
                drg_h = $drag.outerHeight(),
                drg_w = $drag.outerWidth(),
                pos_y = $drag.offset().top + drg_h - e.pageY,
                pos_x = $drag.offset().left + drg_w - e.pageX;
            $drag.css('z-index', 1000).parents().on("mousemove", function(e) {
                $('.draggable').offset({
                    top:e.pageY + pos_y - drg_h,
                    left:e.pageX + pos_x - drg_w
                }).on("mouseup", function() {
                    $(this).removeClass('draggable').css('z-index', z_idx);
                });
            });
            e.preventDefault(); // disable selection
        }).on("mouseup", function() {
            if(opt.handle === "") {
                $(this).removeClass('draggable');
            } else {
                $(this).removeClass('active-handle').parent().removeClass('draggable');
            }
        });

    }
})(jQuery);</code></pre>
<h4>Usage</h4>
<pre rel="jQuery" class="lang-js"><code>$('div').drags();</code></pre>
<h4>Demo</h4>
<pre class="codepen" data-type="result" data-href="zdsty" data-user="chriscoyier" data-host="http://codepen.io"><code></code></pre>
<p><script async src="http://codepen.io/assets/embed/ei.js"></script></p>
]]></content:encoded>

			<wfw:commentRss>http://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/feed/</wfw:commentRss>
			<slash:comments>27</slash:comments>

						
		</item>

	
		<item>
			<title>Add Active Navigation Class Based on URL</title>
			<link>http://css-tricks.com/snippets/jquery/add-active-navigation-class-based-on-url/</link>
			<comments>http://css-tricks.com/snippets/jquery/add-active-navigation-class-based-on-url/#comments</comments>
			<pubDate>Tue, 17 Jul 2012 14:06:40 +0000</pubDate>
			<dc:creator>Chris Coyier</dc:creator>
				<guid isPermaLink="false">http://css-tricks.com/?page_id=17550</guid>

			<description><![CDATA[<p>Ideally you output this class from the server side, but if you can't...   </p>
<p>Let's say you have navigation like this:</p>
<code>&#60;nav&#62;
	&#60;ul&#62;
		&#60;li&#62;&#60;a href="/"&#62;Home&#60;/a&#62;&#60;/li&#62;
		&#60;li&#62;&#60;a href="/about/"&#62;About&#60;/a&#62;&#60;/li&#62;
		&#60;li&#62;&#60;a href="/clients/"&#62;Clients&#60;/a&#62;&#60;/li&#62;
		&#60;li&#62;&#60;a href="/contact/"&#62;Contact Us&#60;/a&#62;&#60;/li&#62;
	&#60;/ul&#62;
&#60;/nav&#62;	</code>
<p>And you are at the URL:</p>
<p><strong>http://yoursite.com/about/team/</strong></p>
<p>And you want the About link to get a class of "active" so you can visually indicate it's the active navigation.</p>
<code>$(function() {
  $('nav a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
});</code>
<p>Essentially that will match links in the nav who's href &#8230;</p>]]></description>

			<content:encoded><![CDATA[<p>Ideally you output this class from the server side, but if you can't...   </p>
<p>Let's say you have navigation like this:</p>
<pre rel="HTML" class="lang-html"><code>&lt;nav&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="/about/"&gt;About&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="/clients/"&gt;Clients&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="/contact/"&gt;Contact Us&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/nav&gt;	</code></pre>
<p>And you are at the URL:</p>
<p><strong>http://yoursite.com/about/team/</strong></p>
<p>And you want the About link to get a class of "active" so you can visually indicate it's the active navigation.</p>
<pre rel="jQuery" class="lang-js"><code>$(function() {
  $('nav a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
});</code></pre>
<p>Essentially that will match links in the nav who's href attribute begins with "/about" (or whatever the secondary directory happens to be).</p>
]]></content:encoded>

			<wfw:commentRss>http://css-tricks.com/snippets/jquery/add-active-navigation-class-based-on-url/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>

						
		</item>

	
</channel>

</rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (User agent is rejected)
Content Delivery Network via cdn.css-tricks.com

 Served from: css-tricks.com @ 2013-05-25 07:25:05 by W3 Total Cache -->