<?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>Elzo Valugi &#187; selectors</title>
	<atom:link href="http://blog.valugi.ro/tag/selectors/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.valugi.ro</link>
	<description>$professional_web_surfing tail -f /dev/things/that/happen &#62; blog</description>
	<lastBuildDate>Sat, 03 Dec 2011 02:05:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Easiest &#8220;check all&#8221; ever with jQuery made even more &#8230; easy</title>
		<link>http://blog.valugi.ro/2009/08/17/easiest-check-all-ever-with-jquery-made-even-more-easy/</link>
		<comments>http://blog.valugi.ro/2009/08/17/easiest-check-all-ever-with-jquery-made-even-more-easy/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 10:09:54 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[selectors]]></category>
		<category><![CDATA[semantics]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=352</guid>
		<description><![CDATA[How to improve some JavaScript. Check full post.]]></description>
			<content:encoded><![CDATA[<p>I was reading some tweets and I got to this <a href="http://briancray.com/2009/08/06/check-all-jquery-javascript/">post</a>, which can be improved.</p>
<p>First the html. Don&#8217;t use divs for layout purposes.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;fieldset&gt;
	// these will be affected by check all
&lt;div&gt;
&lt;input id=&quot;checkall&quot; type=&quot;checkbox&quot; /&gt; Check all&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;/fieldset&gt;
&lt;fieldset&gt;
	// these won't be affected by check all; different fieldset
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;/fieldset&gt;</pre></div></div>

<p>The original post divs are nonsense in terms of usability and semantics. Loose them as the original author just needed some BR tags.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;fieldset&gt;
&lt;input id=&quot;checkall&quot; type=&quot;checkbox&quot; /&gt; Check all 
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&lt;/fieldset&gt;
&lt;fieldset&gt;
	// these won't be affected by check all; different fieldset
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&nbsp;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&nbsp;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&lt;/fieldset&gt;</pre></div></div>

<p>This is the original javascript:<br />
<code class="javascript"><br />
$(function () { // this line makes sure this code runs on page load<br />
$('#checkall').click(function () {<br />
$checkall = $(this); OK<br />
$close = $checkall.parents('fieldset:eq(0)').find('input'); // this is called $close but it should be $elements or something<br />
$checkall.attr('checked') !== true ? $close.removeAttr('checked') : $close.attr('checked', 'checked'); // see my version down<br />
});<br />
});<br />
</code><br />
The javascript can be shortened and I preffer using native functions like <strong>is()</strong>, pseudoselectors like <strong>:checked</strong>, and <strong>boolean</strong> values when accepted instead of strings.</p>
<p><code class="javascript"><br />
$('#checkall').click( function () {<br />
var all= $(this).siblings();<br />
$(this).is(':checked') ? all.attr('checked', true) : all.attr('checked', false);<br />
});<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2009/08/17/easiest-check-all-ever-with-jquery-made-even-more-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

