<?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>1stwebdesigner - Graphic and Web Design Blog &#187; webdev</title>
	<atom:link href="http://www.1stwebdesigner.com/tag/webdev/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.1stwebdesigner.com</link>
	<description>1stwebdesigner is a design blog dedicated to bloggers, freelancers, web-developers and designers. Topics focus on web design and inspirational articles.</description>
	<lastBuildDate>Sun, 12 Feb 2012 13:09:13 +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>An Introduction to Object Oriented CSS</title>
		<link>http://www.1stwebdesigner.com/css/object-oriented-css/</link>
		<comments>http://www.1stwebdesigner.com/css/object-oriented-css/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 10:00:26 +0000</pubDate>
		<dc:creator>Ranjith Kumar</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[CSS design]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=49102</guid>
		<description><![CDATA[With richer interactions and media heavy pages mushrooming on the web, creating web pages, which load faster and respond well has become a challenge. Separating the content, presentation and behavior of a page using HTML, CSS and JS, is not the only thing that front-end engineers have to concentrate on nowadays. The limelight is now [...]]]></description>
			<content:encoded><![CDATA[<p>With richer interactions and media heavy pages mushrooming on the web, creating web pages, which load faster and respond well has become a challenge. Separating the content, presentation and behavior of a page using HTML, CSS and JS, is not the only thing that front-end engineers have to concentrate on nowadays. The limelight is now on the performance of the pages, cleanliness and leanness of the code within, scalability and reusability of CSS, and the semantic correctness of the markup.</p>
<p>There are a handful of frameworks, techniques and approaches that are built towards this goal of maintainability, scalability and reusability of CSS. Each of them is having its own pros and cons. But, this is not a stage to elaborate on all of them.</p>
<p>This article is an introduction to implementing the concept of ‘Object Oriented Programming’ in building CSS for high scale websites and applications, with an eye on maintainability and reusability.</p>
<p><span id="more-49102"></span></p>
<h2><strong>What is OO CSS?</strong></h2>
<p><img class="alignleft size-full wp-image-49113" style="padding: 10px;" title="thmb3" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thmb3.jpg" alt="" width="180" height="150" />The concept of ‘Object Oriented Programming’, is widespread among developers, and forms the basic for any modern programming language. Features like data abstraction, modularity and inheritance make it a favorite in coding large-scale applications.</p>
<p>Object Oriented CSS, as the name suggests, is implementing the concepts of OOP in structuring and building CSS rules, which are easy to reuse, thereby reducing the loading time and increasing the performance of web pages incredibly! The key point here is, to identify, build and style modular reusable ‘objects’ in a page, and to reuse it in multiple instances by extending them with additional features wherever needed. Here an ‘object’ refers to the basic HTML markup and its CSS rules. Apparently, here, the key challenge is going to be, identifying the ‘object’ and building rules for it.</p>
<p>This is neither a framework nor a technology, but an approach adopted in building the rules, so as to make the code more reusable, maintainable and scalable. You may already have been making use of this concept in coding your style-sheet for years, but may not be aware of this terminology :).</p>
<p>A UI engineer at Yahoo (‘<a href="http://www.stubbornella.org/content/nicole-sullivan/" target="_blank">Nicole Sullivan’ )</a> coined the term. She had made a number of presentations on the topic on various big stages (<a href="http://developer.yahoo.net/blogs/theater/archives/2009/03/website_and_webapp_performance.html">http://developer.yahoo.net/blogs/theater/archives/2009/03/website_and_webapp_performance.html</a>) and is also included in a feature on <a href="http://www.wait-till-i.com/2009/03/24/ada-lovelace-day-women-in-technology-i-admire/" target="_blank">Women in Technology</a>.</p>
<p>Nicole, who has been hired by Facebook recently, for optimizing the CSS and web page performance, has been leading the way in implementing this approach in the pages for the social networking giant, and the results are to be seen. A faster loading FB, with significantly less response time! This is exactly what this approach of building CSS promises to give back. But again, like all other frameworks, this too has pitfalls and advantages which we shall discuss in detail.</p>
<p>Following are some key aspects in object-oriented approach to CSS building:</p>
<ol>
<li>Create a component library</li>
<li>Separate container and content / Avoid Location dependent styles</li>
<li>Separate Structure and skin</li>
<li>Extend base objects using class names</li>
<li>Stick to semantic class names</li>
</ol>
<h3><strong>Create a component library</strong></h3>
<p><img class="alignleft size-full wp-image-49114" style="padding: 10px;" title="thumb4" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb42.jpg" alt="" width="180" height="150" />This is the first thing to do, while building a OO CSS framework for your application, and this is the most time consuming process too. You will have to carefully study the screens of the app, and come up with the recurring reusable UI patterns, and will have to create a library consisting of HTML markup and respective CSS rules of all such components first. This may take some initial time, as you may need to filter out the components and find out the basic structure of a component, and its variations along different screens.</p>
<p>E.g. For a blog, ‘metadata (Refer to the marked area in the figure below)’ will be present in multiple instances of a page. After closer scrutiny, you will come to know that, all the metadata can have the same HTML markup, and the variations can be addressed using CSS (the font size, color, margin and padding are different in each of the occurrences of metadata component). Select a markup, as a base structure, in which you can accommodate majority of the elements that possibly can come in the particular component.</p>
<p><img class="size-full wp-image-49124 alignnone" style="padding: 10px;" title="thumb1" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb13.jpg" alt="" width="574" height="430" /></p>
<p>In our example our basic structure of the ‘metadata’ component will be:</p>
<h3>Base Markup</h3>
<pre class="brush: xml; title: ; notranslate">

&lt;p class=”metadata”&gt;&lt;a&gt;Author name&lt;/a&gt;commented on&lt;a&gt;21-02-2010&lt;/a&gt;@&lt;/p&gt;
</pre>
<h3>Base rule</h3>
<pre class="brush: xml; title: ; notranslate">

.metadata{font-size:1.2em; text-align:left; margin:10px 0;}
</pre>
<p>Thus, ‘metadata’ can be now independently used within any other element in the markup, and will have a consistent look and feel, irrespective of where it is used. But as we can see in the figure above, there are multiple variations of the component. This we will tackle using CSS, and will be discussing in the following points.</p>
<p>This way, figure out all the reusable components, and create rules and markup, and group them separately in the CSS file. (It’s even fine to create a separate CSS for the component library, and then merge it with others later during deployment.)</p>
<h3><strong>Separate Content from Container / Avoid location dependent styles</strong></h3>
<p>This is one of the primary requirements of following an OO approach to building CSS files. The core idea here is to consciously differentiate the rules of containers and the content that comes within them, so that content can be plugged into any containers irrespective of their parents.</p>
<p>Often while building large-scale CSS rules there will be instances where a single component will be appearing differently in various instances, when put in different containers. One of the solutions adopted by front-end engineers, for addressing this problem was to assign location dependent selectors to that particular component.</p>
<p>E.g. With reference to the example used in the previous point, where there are multiple variations of the same component – ‘metadata’, each instance can be given location dependent rules by combining the base class ‘metadata’ with the relevant classes/IDs for the containers. i.e.,</p>
<p>‘metadata’ in a blog post can be styled as: <em>.post .metadata{overriding rules}</em><br />
‘metadata’ in a comment can be styled as: <em>.comment .metadata{overriding rules}</em><br />
‘metadata’ in a comment can be styled as: <em>.comment .metadata{overriding rules}</em></p>
<p>The OOCSS approach advocates avoiding this type of usage. Instead <strong>extend</strong> the base class by adding more classes, thereby extending the attributes of the base component to match the variation. We shall discuss the concept of extending the base class in the following points.</p>
<h3><strong>Separate structure and skin</strong></h3>
<p><a rel="attachment wp-att-49115" href="http://www.1stwebdesigner.com/css/object-oriented-css/attachment/thumb5-3/"><img class="alignleft size-full wp-image-49115" style="padding: 10px;" title="thumb5" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb52.jpg" alt="" width="180" height="150" /></a>In the first point ‘Creating component library’, we discussed the importance of identifying reusable components, and building base classes and base structures for them. While creating those base rules, an important thing to keep in mind is to separate the structure and skin. In other words, while defining a base class in the component library, we should not create skin-level rules, like width, height, background images, border styles, etc, that can make the component more specific to a certain container.</p>
<p>E.g. For our base class, ‘metadata’ with the following rule</p>
<pre class="brush: css; title: ; notranslate">
.metadata{font-size:1.2em; margin:10px 0;},
</pre>
<p>Adding more skin-level rules as below,</p>
<pre class="brush: css; title: ; notranslate">

.metadata{font-size:1.2em; margin:10px 0; &lt;strong&gt;width:500px; background-color:#efefef; color:#fff;&lt;/strong&gt;},
</pre>
<p>can make it more of a specific component than a generic one, thereby making it difficult to reuse it in many other containers, which would need it to be rendered in a different ‘skin’. Also another danger of not separating structure and skin will be the ‘Specificity war’.</p>
<h3><strong>Extend base objects using class names</strong></h3>
<p><a rel="attachment wp-att-49116" href="http://www.1stwebdesigner.com/css/object-oriented-css/attachment/thumb6-3/"><img class="alignleft size-full wp-image-49116" style="padding: 10px;" title="thumb6" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb62.jpg" alt="" width="180" height="150" /></a>As discussed in the second point ‘Separate content from container’, avoiding the usage of contextual selectors will make the content independent from their parent containers and hence will be truly usable across the application. So how do we instantiate the variations of the same object in different containers? What is the solution? Well here comes the concept of <strong>extending</strong> the base ‘object’ (again another term coined by Nicole Sullivan), by adding more class names to it depending on the context, rather than tightly coupling the object with the class names of the containers in which it is to be placed.</p>
<p>E.g. In the first figure of the ‘metadata’ object, where the same object needs to be rendered differently in various containers,</p>
<p>The HTML markup of each of them will look like:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;p class=”metadata commentmetadata”&gt;&lt;a&gt;Authorname&lt;/a&gt;commented on&lt;a&gt;21-02-2010&lt;/a&gt;@&lt;/p&gt;
&lt;p class=”metadata postmetadata”&gt;&lt;a&gt;Authorname&lt;/a&gt;commented on&lt;a&gt;21-02-2010&lt;/a&gt;@&lt;/p&gt;
&lt;p class=”metadata authorlistmetadata”&gt;&lt;a&gt;Authorname&lt;/a&gt;commented on&lt;a&gt;21-02-2010&lt;/a&gt;@&lt;/p&gt;
</pre>
<p>The CSS rules will be:</p>
<pre class="brush: css; title: ; notranslate">

.metadata{font-size:1.2em; margin:10px 0;}
.commentmetadata{font-size:1em; margin:0 0 10px 0; color:#063070; }
.postmetadata{ color:#063070; }
.authormetadata{ color:#fff; }
</pre>
<p>This is a very simple demonstration, to comprehend the concept of implementing OO programming. As the size of the app becomes larger, the UI patterns will become more complex, and there lies the actual challenge and advantage of using such an approach.</p>
<h3><strong>Stick to semantic class names</strong></h3>
<p>A challenge in building CSS for high-scale web applications is to logically come up with meaningful class / ID names matching with the context and moreover making sure, they are reusable and still make sense. With the concept of ‘extending’ base objects, it’s easy to fall into the practice of creating ‘presentational class names’. Some easy examples are ‘leftCol’, ‘redText’, ‘midCol’, ‘bigText’, ‘bolderText’ etc. Such class names are not reusable and are a hindrance to scalability.</p>
<p>Always stick to logical and semantic class names relating to the logical meaning of the component, rather than its presentational meaning. It means, instead of giving the text block with a yellow background color, the class name ‘yellowText’, ‘notification’ would be a more sensible name, as it is a notification element that pops out to notify some activities within the system.<strong> </strong></p>
<h3><strong>Pros and Cons?</strong></h3>
<p>Following such an approach of building CSS has its own pitfalls and advantages</p>
<p>Here are a few cases, where adopting such a framework ‘may’ backfire:</p>
<ol>
<li>OOCSS is suited to really large websites / application which are filled with reusable components. It may not give desired results in smaller websites and applications. So decide sensibly depending on the size of the work in hand</li>
<li>If not smartly used, creating the component library can turn out to be a mess, and become a maintenance nightmare for other coders</li>
<li>Documentation is a must. Each block of code should be clearly commented out with the right points for other coders to absorb the concept, which otherwise can become too tedious in case of a knowledge transition</li>
</ol>
<p>Some obvious advantages of adopting this approach are:</p>
<ol>
<li>Less lines of CSS code</li>
<li>Cleaner HTML markup, with logically sensible class names and hierarchy</li>
<li>Semantic markup, means more SEO friendly pages</li>
<li>Far better page optimization, with much faster loading times, since most of the components are reused</li>
<li>Scalable markup and CSS code, where more components can be added into the library without disturbing other components, as the base objects are independent of any other containers</li>
<li>Easily theme-able layouts, since changes to the base object can completely change almost the whole presentation layer instantly</li>
</ol>
<h3><strong>Courtesy &amp; Resources</strong></h3>
<p><a href="http://www.stubbornella.org/content/2009/02/28/object-oriented-css-grids-on-github/">http://www.webdirections.org/blog/object-oriented-css-the-video/</p>
<p>http://www.stubbornella.org/content/2009/02/28/object-oriented-css-grids-on-github/</a></p>
<p><a href="http://www.iconfinder.com">http://www.iconfinder.com</a> for all the icon resources</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/css/object-oriented-css/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Bridging the Designer-Developer Gap</title>
		<link>http://www.1stwebdesigner.com/design/bridging-designer-developer-gap/</link>
		<comments>http://www.1stwebdesigner.com/design/bridging-designer-developer-gap/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 10:00:38 +0000</pubDate>
		<dc:creator>Ranjith Kumar</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[team work]]></category>
		<category><![CDATA[user experience]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=48835</guid>
		<description><![CDATA[How are ‘Right brainers’ different from ‘Left Brainers’? Well, this is not a zoology question being thrown at you. If you are working on a team dealing with websites / apps, and if there is a design team working with a team of developers, you probably would be witnessing the answer to this question every [...]]]></description>
			<content:encoded><![CDATA[<p>How are ‘Right brainers’ different from ‘Left Brainers’?</p>
<p>Well, this is not a zoology question being thrown at you. If you are working on a team dealing with websites / apps, and if there is a design team working with a team of developers, you probably would be witnessing the answer to this question every single day you work!</p>
<p>This is an inevitable fact, and it is this difference that makes the two communities thrive, and the best team is the one which finds a way to converge the collective wisdom of both these ‘species’ into the final stage of their deliverable – An ideal human-machine interaction experience, filled with life and satisfaction.</p>
<p>But in reality, most of the teams stumble at this moment, when the ideologies of both of them should be given weight and injected into the final product, and this shortcoming, is the whole essence of this article.</p>
<p><span id="more-48835"></span></p>
<h2><strong>What is the gap?</strong></h2>
<p><img class="size-full wp-image-48940 alignleft" style="padding: 10px;" title="thumb1" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb11.jpg" alt="" width="180" height="150" />Every man-made object is created based on a single principle. Make a task easier and faster to accomplish, and for each object/gadget, the ‘form’ (the physical appearance) and ‘function’ (the way it responds and processes the task) plays an important role. The same logic prevails, when it comes to computer-based systems also. Here the ‘form’ is &#8211; ‘Look and Feel’ (Usability of UI and Interaction), and ‘function’ is – ‘performance and efficiency’ (Efficiency of the empowering technology implementation)</p>
<p>Talking about computer based interfaces, designers are in charge of ‘Form’, and developers, ‘Function’. In short an app is the work of developers, hidden below the skin and skeleton created by the designers. The vital part is to retain the ‘skin and skeleton’ till the end product without any change whatsoever, and this is the most unattended part of the process in most of the teams. Results are half baked products that are unusable, in spite of the numerous hours of effort put in by the designers, after painstakingly drafting wireframes, Visual Comps, and Prototypes, only to find all those ‘details’ ignored vehemently in the end product. It is not a pleasant experience to find a deployed app, without that gradient on hover implemented, after you spent hours finalizing the color scheme.</p>
<p>This ‘erosion’ in the ‘form’ proposed by the design team, when the product reaches its final stages of development constitutes the majority of the ‘Gap’.</p>
<h2><strong>What creates this gap?</strong></h2>
<p><strong> </strong>There is an array of reasons we can attribute such a gap to. Here are some practical points, which play an important role in bridging the gap.</p>
<ul>
<li>The missing link – Front-end Engineering</li>
<li>Awareness of design principles and usability</li>
<li>Team work</li>
<li>The ‘Hybrid’ designer</li>
<li>Passion for the finished product</li>
<li>Designer – Developer meetings</li>
</ul>
<h2><strong>The missing link – Front-end Engineering</strong></h2>
<p style="padding-left: 30px;"><img class="alignleft size-full wp-image-48941" style="padding: 10px;" title="thumb2" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb21.jpg" alt="" width="180" height="150" />Often, the role of a design team comes to an end by delivering the Visual comps, by the visual designer, out of the wireframes. The dev team takes over, and from here the erosion starts slowly, ignoring and omitting the details in the design, concentrating only on the ‘function’, to the extent that, the page looks completely disconnected from the visual design.</p>
<p>So apparently, the gap between the Visual comps and the functional page is where the actual work needs to be done.</p>
<p>A front-end engineer comes in really handy in such a scenario, and forms an integral part of a design team, by considerably reducing the gap between the visual comps, and the functional page. An ideal candidate for this position should have expertise in XHTML, CSS and JS, which enables him to create clickable prototypes matching the Visual comps, or at least they&#8217;re as close as possible. By the addition of such a skill set, the dev team can concentrate more on ‘function’, as they always do, and the design team can be rest assured that, all the details are captured visually as well.</p>
<h2>Awareness of design principles and usability</h2>
<p><img class="alignleft" title="thumb6" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb61.jpg" alt="" width="180" height="150" />A developer is not destined to just code the application to perfection. It’s an added boon, in having a design conscious developer on board and avoid some basic mistakes which may have arisen due to lack of basic knowledge of design. Most of the shortcomings and problems that widen the gap between the designer and developer, is the missing knowledge of design principles, and failing to understand the importance of a good design and how it plays an important role in increasing the credibility and usability of a system. A design team working in isolation from a dev team, and vice versa, is not going to be able to bridge the gap. In fact, both the team should co-exist and interact by exchanging ideas and conducting knowledge sharing sessions and talks. This can help build a rapport as well as create a common ground as far as awareness of design is concerned.</p>
<p>This is really important for the sustained growth of a team as a whole, and also helps in eliminating critical differences at any point during the life of an application</p>
<h2>Teamwork</h2>
<p><img class="alignleft" title="thumb3" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb31.jpg" alt="" width="180" height="150" />It&#8217;s the team which gets the credit at the end of a successful project, and every member contributes his part to the bigger cause. Working in a team of designers and developers is always going to be a challenge, where ideas are subject to conflict and solutions are always a result of brainstorming and negotiation.</p>
<p>As always, it takes a lot of team playing skills, to convince the developer to stick to the design guidelines and come up with an appealing application that works and looks good at the same time. Creating a good rapport with the team members is vital, and often it can solve most of the shortcomings related to bridging the designer-developer gap. Both the teams should be willing to tackle any obstacles together, whether design or development related.</p>
<h2>The ‘Hybrid’ designer</h2>
<p><img class="alignleft" title="thumb4" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb41.jpg" alt="" width="180" height="150" />Delivery of XHTML pages to the dev team, alone doesn’t end the role of the design team in the whole process. He should be able to keep a close tab on the development process and should ideally understand the basics of coding, to tackle a possible deviation from the design guidelines, due to technical limitations and reasons native to the technology used.</p>
<p>This makes a multi-skilled designer, an integral part of any design team. At a time where people are hired based on core skill set expertise, hybrid designers can make the real difference, and its high time the hiring managers realize this and open up the doors for generalization also, rather than concentrate only on specialization!</p>
<h2>Passion for the ‘Finished product’</h2>
<p><img class="alignleft" title="thumb5" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/06/thumb51.jpg" alt="" width="180" height="150" />Most of the time, an output-oriented team can have adverse effect on the final deliverable if they don&#8217;t see the bigger picture, which is the product itself!</p>
<p>It is the passion to see the final product emerge perfectly, which is missing among most of the team members, which results in those loopholes and shortcomings in the whole product. It’s a team effort and each individual should see that their contribution is towards a larger goal and shed the mindset of just meeting their individual milestones. This is an area where a closely knit team, scores over large teams, with hundreds of members, working together but yet in isolation.</p>
<p>Team rapport is the underlining factor!</p>
<h2>Designer – Developer meetings</h2>
<p>As mentioned, it is really important to take the ideas of both the designers and developers and make it something productive and useful. Meetings comprising both these &#8216;species&#8217; together would serve the purpose. There would be some initial hiccups, due to the contrasting opinions, but believe me, its worth the effort, and the rapport and confidence that such a meeting instills within the team will be really commendable and helpful for completing better products in the end.</p>
<h2><strong>The Result</strong></h2>
<p>With the awareness of usability and user experience moving up the ladder, products are going to be judged based on their performance and ease of use, and it&#8217;s really vital to bridge this gap as early as possible, and move towards the world of usable and straight forward human-machine interaction, which leaves an ever lasting impression on the user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/design/bridging-designer-developer-gap/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Presenting the Great New Features of WordPress 3.1</title>
		<link>http://www.1stwebdesigner.com/wordpress/presenting-wordpress-3-1/</link>
		<comments>http://www.1stwebdesigner.com/wordpress/presenting-wordpress-3-1/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 06:55:19 +0000</pubDate>
		<dc:creator>Saad Bassi</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[3.1]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[webdesign]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=41784</guid>
		<description><![CDATA[Folks at WordPress have just released WordPress 3.1 (Code name “Reinhardt”), 14th version of World’s most famous and award-winning publishing software. This release has some fantabulous features like Internal Linking and a WordPress.com styled admin bar on front end which makes it very easy to visit most used features of back-end. Read on to have [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Folks at <a href="http://wordpress.org">WordPress</a> have just <a href="http://wordpress.org/news/2011/02/threeone/">released</a> WordPress 3.1 (Code name “Reinhardt”), 14th version of World’s most famous and award-winning publishing software. This release has some fantabulous features like Internal Linking and a WordPress.com styled admin bar on front end which makes it very easy to visit most used features of back-end. Read on to have an overview of some major features of this release.<span id="more-41784"></span></p>
<h3>Internal Linking</h3>
<p>We can’t stress enough on the importance of Internal linking for SEO of your WordPress blog. To be honest, the process of Internal linking was pretty painful unless you would use some <a href="http://wordpress.org/extend/plugins/insights/">plugins</a> or hacks to find relevant posts for internal linking. With WordPress 3.1 this is a breeze now. WordPress now have built-in functionality to link your new content with already published content. Below is a screenshot of this kick-ass functionality.</p>
<p style="text-align: center;"><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/wordpress-3-1-internal-linking-1.png"><img class="size-full wp-image-41787 aligncenter" title="wordpress-3-1-internal-linking-1" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/wordpress-3-1-internal-linking-1.png" alt="" width="505" height="468" /></a></p>
<p>I’ve updated my personal blog and I have to say I’m in love with it.</p>
<h3>Admin Bar</h3>
<p>If you visit WordPress.com as a logged-in user, you will see a bar at top of page which gives you shortcuts to important and most used areas of backend. With WordPress 3.1, you can enjoy the same functionality on self hosted blogs ;)</p>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/wordpress-3-1-admin-bar.png"><img class="aligncenter size-full wp-image-41790" title="wordpress-3-1-admin-bar" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/wordpress-3-1-admin-bar.png" alt="" width="500" height="111" /></a></p>
<p>However if you don’t like this functionality, you can always disable it by going to your user profile.</p>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/wp-admin-bar-disable.png"><img class="aligncenter size-full wp-image-41792" title="wp-admin-bar-disable" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/wp-admin-bar-disable.png" alt="" width="500" height="257" /></a></p>
<h3>Admin area Tweaks</h3>
<p><strong>Ajaxification:</strong> Latest version of WordPress also has improved the posts area too with Ajaxification. You don&#8217;t have to reload pages while searching for posts. Also you can go to specific page number by entering page number itself in Posts admin area. Below is a video for this functionality to even describe it better.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="345" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="flashvars" value="i=175492" /><param name="allowFullScreen" value="true" /><param name="src" value="http://screenr.com/Content/assets/screenr_1116090935.swf" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="345" src="http://screenr.com/Content/assets/screenr_1116090935.swf" allowfullscreen="true" flashvars="i=175492"></embed></object></p>
<p><strong>Overhauled Blue Theme of Admin area</strong> is also included in this release which looks stunning, a pretty good job done by UX team of WordPress.</p>
<p><img class="aligncenter size-full wp-image-41796" title="blue-admin-theme" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/blue-admin-theme.jpg" alt="" width="550" height="267" /></p>
<p><span style="font-weight: normal;">Now we will cover new functionality from developer&#8217;s point of view.</span></p>
<h3>Post Formats</h3>
<p>Battle between WordPress and Tumblr is an open secret. Both of them have been trying to grab each other&#8217;s user base. Here at 1wd we are die-hard fans of WordPress and I am not reluctant in saying that I&#8217;m biased towards WordPress :) With these new <a href="http://codex.wordpress.org/Post_Formats">Post formats</a>, WordPress provides you out of the box functionality for creating and styling different type of posts i.e links,chat,photo etc.</p>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/post-formats.jpg"><img class="aligncenter size-full wp-image-41797" title="post-formats" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2011/02/post-formats.jpg" alt="" width="309" height="118" /></a></p>
<p><a href="http://ottopress.com/2010/post-types-and-formats-and-taxonomies-oh-my/">Here</a> is a pretty good write-up on post formats by core contributor of WordPress, Otto.</p>
<h3>An Even Better CMS</h3>
<p>WordPress 3.1 allows you to create advanced taxonomies and call custom field queries.Result of which is WordPress is even better and comprehensive CMS. Matt Mullenweg, Founder of WordPress summed up this pretty well in release post of 3.1.</p>
<blockquote><p>There’s a bucket of candy for developers as well, including our new <strong>Post Formats support</strong> which makes it easy for themes to create portable tumblelogs with different styling for different types of posts, <strong>new CMS capabilities</strong> like archive pages for custom content types, a <strong>new Network Admin</strong>, an overhaul of the import and export system, and the ability to perform<strong> advanced taxonomy and custom fields queries</strong>.</p>
<p>With the 3.1 release, <strong>WordPress is more of a CMS than ever before</strong>. The only limit to what you can build is your imagination.</p></blockquote>
<p><a href="http://codex.wordpress.org/Version_3.1">Here</a> is a list of complete features and changelog in WordPress 3.1. All these exciting changes demand that you should upgrade your WordPress right now :D with no time delay. This update is available in your dashboard and you can download it as well from <a href="http://wordpress.org/download/">here</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/wordpress/presenting-wordpress-3-1/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>jQuery for Complete Beginners: Part 4</title>
		<link>http://www.1stwebdesigner.com/tutorials/jquery-beginners-4/</link>
		<comments>http://www.1stwebdesigner.com/tutorials/jquery-beginners-4/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 10:00:05 +0000</pubDate>
		<dc:creator>Jack Franklin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=14050</guid>
		<description><![CDATA[Welcome back to jQuery for Beginners. Just a quick recap first &#8211; in the first two weeks we covered the very basics of jQuery and interacting with elements. Last time round we made an accordion &#8211; something which taught us a few of the jQuery special animation functions that are built in to jQuery. Today [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.1stwebdesigner.com/tutorials/jquery-beginners-4/"><img class="alignleft size-full wp-image-14053" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/thumb4.png" alt="" width="150" height="150" /></a> Welcome back to jQuery for Beginners. Just a quick recap first &#8211; in the first two weeks we covered the very basics of jQuery and interacting with elements. Last time round we made an accordion &#8211; something which taught us a few of the jQuery special animation functions that are built in to jQuery. Today we will be using those functions and a bit more as we look at creating a nice looking Gallery page, built with HTML and CSS, and then adding some nice interactive effects with jQuery.</p>
<p>&nbsp;</p>
<p><span id="more-14050"></span></p>
<p>Be sure to check the previous parts:</p>
<ul>
<li><a href="http://www.1stwebdesigner.com/tutorials/jquery-beginners-1/">Part 1</a></li>
<li><a href="http://www.1stwebdesigner.com/tutorials/jquery-complete-beginners-part-2/">Part 2</a></li>
<li><a href="http://www.1stwebdesigner.com/tutorials/jquery-for-complete-beginners-part-3/">Part 3</a></li>
</ul>
<p>You can see the <a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/07/jquery-beginners-4/index.html">live demo</a> here. You can also download the source code <a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/jquery-beginners-4.zip">here</a>.</p>
<p>Firstly, open up a new HTML page, add the basic HTML code and then include jQuery like so:</p>
<pre class="brush: xml; title: ; notranslate">
	&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;

	&lt;/script&gt;
</pre>
<p>I&#8217;ve also added another script tag that is blank. This is where our code will go. Notice that when I included jQuery from the Google CDN (we covered this back in the first post) I&#8217;ve used &#8220;jquery/1/jquery.min.js&#8221;. Using just &#8220;1&#8243; means we will automatically be given the most recent version of jQuery, until we get to jQuery 2, which is a fair way off for now. You could be much more specific, of course, if you wished, but for me it makes logical sense to keep up to date with the most recent versions.</p>
<p>Now we&#8217;ve got that sorted, I&#8217;ve got a basic HTML structure for our gallery, ready made with five images. If you go to the bottom of this post, you can download them, along with the completed code.</p>
<pre class="brush: xml; title: ; notranslate">
div id=&quot;gallery&quot;&gt;
		&lt;div class=&quot;galleryitem&quot;&gt;&lt;img src=&quot;image1.jpg&quot; alt=&quot;A beautiful Sunset over a field&quot; /&gt;&lt;p&gt;A beautiful Sunset over a field&lt;/p&gt;&lt;/div&gt;
		&lt;div class=&quot;galleryitem&quot;&gt;&lt;img src=&quot;image2.jpg&quot; alt=&quot;Some penguins on the beach&quot; /&gt;&lt;p&gt;Some penguins on the beach&lt;/p&gt;&lt;/div&gt;
		&lt;div class=&quot;galleryitem&quot;&gt;&lt;img src=&quot;image3.jpg&quot; alt=&quot;The sun trying to break through the clouds&quot; /&gt;&lt;p&gt;The sun trying to break through the clouds&lt;/p&gt;&lt;/div&gt;
		&lt;div class=&quot;galleryitem&quot;&gt;&lt;img src=&quot;image4.jpg&quot; alt=&quot;Palm tress on a sunny day&quot; /&gt;&lt;p&gt;Palm tress on a sunny day&lt;/p&gt;&lt;/div&gt;
		&lt;div class=&quot;galleryitem&quot;&gt;&lt;img src=&quot;image5.jpg&quot; alt=&quot;The sun bursting through the tall grass&quot; /&gt;&lt;p&gt;The sun bursting through the tall grass&lt;/p&gt;&lt;/div&gt;
	&lt;/div&gt;
</pre>
<p>Next up we will apply some CSS styling to make it look nicer. Seeing as this is a jQuery tutorial, I&#8217;m not going to explain much of this. Essentially I&#8217;m just adding a border, styling the font and floating the images so they display next to each other.</p>
<pre class="brush: css; title: ; notranslate">
	#gallery {width: 960px; margin: 0 auto;}
		.galleryitem {width: 300px; height: 300px;float: left; font-family: Lucida Sans Unicode, Arial; font-style: italic; font-size: 13px; border: 5px solid black; margin: 3px;}
		.galleryitem img {width: 300px;}
		.galleryitem p {text-indent: 15px;}
</pre>
<p>And your page should look something like this:</p>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/jquery4-1.jpg"><img class="alignleft size-full wp-image-14054" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/jquery4-1.jpg" alt="" width="520" height="340" /></a></p>
<p>Looks pretty good!</p>
<p>Our next step is going to be some jQuery. At last! We are going to remove the paragraphs and make them appear on hover, with some nice CSS styling to make them look really nice. What I&#8217;ve done is create a CSS id which we will apply to a paragraph when the corresponding image is hovered over:</p>
<pre class="brush: css; title: ; notranslate">
	#galleryhoverp { margin-top: -55px; background-color: black; opacity: 0.5;
		-moz-opacity: 0.5;
		filter:alpha(opacity=50); height: 40px; color: white; padding-top: 10px;}
</pre>
<p>So our first step is to hide all the paragraphs and then resize our gallery items so just the image is displayed. We&#8217;ll also save all our gallery items to a variable for later usage.</p>
<pre class="brush: jscript; title: ; notranslate">
	$('p').hide();
	var galleryItems = $('.galleryitem');
		galleryItems.css('height', '200px');
</pre>
<p>And now lets add an effect for when the gallery item is hovered over. Firstly lets find all the images and save them.</p>
<pre class="brush: jscript; title: ; notranslate">
var images = $('.galleryitem').find('img');
</pre>
<p>The hover function is slightly unusual in that it takes two functions. The first is what should happen when the image is hovered over, the second when the mouse stops hovering over that image.</p>
<pre class="brush: jscript; title: ; notranslate">
	galleryItems.hover(
			function() {
				//when hovered over
			},
			function() {
				//when hovered ends
			}
		)
</pre>
<p>The code is very simple. We just select the next paragraph using the next() function, show it and then give it that id we created a while back. On the hover-out function, we just do the exact opposite:</p>
<pre class="brush: jscript; title: ; notranslate">
galleryItems.hover(
			function() {
				$(this).children(&quot;id&quot;).next('p').show().attr('id', 'galleryhoverp');
			},
			function() {
				$(this).children(&quot;id&quot;).next('p').hide().attr('id', '');
			}
		)
</pre>
<p>And there you go! If you try it out now you should see the paragraphs show when you hover over, and then leave when you change to a different image.</p>
<p>There is one more effect we will add. When you click on an image, it should enlarge, fill the centre of the screen and all the other images disappear. Again, I&#8217;m creating some CSS which we will add to the image we want to display:</p>
<pre class="brush: css; title: ; notranslate">
#singleimagedisplay {width: 800px;}
#singleimagedisplay img {width: 800px;}
#singleimagedisplay a {float: right; color: white;}
</pre>
<p>We&#8217;ll add this code to the image&#8217;s parent &#8211; the div with a class of &#8216;galleryitem&#8217;. The code for the entire click event is below:</p>
<pre class="brush: jscript; title: ; notranslate">
	images.click(function() {
			$(this).parent().attr('id', 'singleimagedisplay').css('height', $(this).height()).siblings().hide();
			$(this).next('p').show().html($(this).next('p').html() + '&lt;a href=&quot;jquery1.html&quot;&gt;Back&lt;/a&gt;');

		})
</pre>
<p>So, when each image is clicked, these are the steps we take:<br />
1. Give the id of &#8216;singleimagedisplay&#8217; to the image&#8217;s parent.<br />
2. Set the height of the image parent to the height of the image. This uses jQuery&#8217;s height() function, which finds the height of the specified item.<br />
3. Select all the other gallery item divs using siblings() and hide them.<br />
4. Edit the paragraph that comes with the image to have a link on the end, which links back to the home page. jQuery&#8217;s HTML function allows us to edit the HTML code with in an item, but only if we put something inside the brackets. Else, it just gets us the value. So .html() gets the code inside the paragraph, and html(&#8216;new stuff&#8217;) changes the content of the paragraph. Bear in mind, if you use .text() or .text(&#8216;hello&#8217;) that will just edit the text, but if you wish to add HTML code inside an item, you need to use html().</p>
<p>And if you check out your page, you will find it works! There is one final issue. When viewing a single image, if you hover out, the paragraph goes away. We don&#8217;t want this, so we need to go back to our hover function and make a slight edit:</p>
<pre class="brush: jscript; title: ; notranslate">
galleryItems.hover(
			function() {
				if($(this).attr('id')!='singleimagedisplay')
				{

					$(this).children(&quot;img&quot;).next('p').show().attr('id', 'galleryhoverp');
				}

			},
			function() {
				if($(this).attr('id')!='singleimagedisplay')
				{
					$(this).children(&quot;img&quot;).next('p').hide().attr('id', '');
				}
			}
		);
</pre>
<p>All we do is see if the id on the item is not set to &#8216;singleimagedisplay&#8217; which means that we are on the main gallery page, and then we can run the code we had originally. And we are done. You can download everything below:</p>
<p>Download the page and images.</p>
<p>I hope you found this a useful lesson, and I will see you next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/tutorials/jquery-beginners-4/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>HTML and Semantics – Conjoined twins of the Future Web !</title>
		<link>http://www.1stwebdesigner.com/design/html-and-semantics-conjoined-twins-of-the-future-web/</link>
		<comments>http://www.1stwebdesigner.com/design/html-and-semantics-conjoined-twins-of-the-future-web/#comments</comments>
		<pubDate>Mon, 31 May 2010 10:00:08 +0000</pubDate>
		<dc:creator>Ranjith Kumar</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[trends]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=15959</guid>
		<description><![CDATA[Around 4-5 years ago, my daily knowledge building and socializing activities went like – read books, attend some sessions/training, visit a friend&#8217;s place, engage in a constructive debate, take a walk @ the nearby park … and so on . But years later … the scenario is slowly changing and I hardly find any time [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.1stwebdesigner.com/development/html-and-semantics-conjoined-twins-of-the-future-web/"><img class="alignleft size-full wp-image-15960" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/htmlnsemantic.jpg" alt="" width="150" height="150" /></a>Around 4-5 years ago, my daily knowledge building and socializing activities went like – read books, attend some sessions/training, visit a friend&#8217;s place, engage in a constructive debate, take a walk @ the nearby park … and so on . But years later … the scenario is slowly changing and I hardly find any time doing at least a few of the items listed above, and a lot more additional items have creeped in to the list!</p>
<p>The technology has taken over, and the collective wisdom of humanity, is slowly getting harnessed onto the most powerful medium today – the WEB ! Kids are more concerned about making more friends on their favorite social-networking site than friends at school / college, we talk through comments and write on walls (I would’ve been happier, if we burn that much calorie to write on an actual wall … but this is something else J). The internet is slowly becoming a part of daily life now.<span id="more-15959"></span> Imagine a day, when you could gather all the data that you would need, fetched from the millions of servers on the web, custom tailored to fit into your global profile page, without needing to go searching deeply into the fathoms of the complex web traffic. Yes, that is where the web is heading towards, and that day will be called – ‘<strong>The day of Semantic Web’</strong>, and the most important players in that era will be none other than our old kid &#8216;HTML&#8217; and the relatively sophisticated kid ‘Semantics’.</p>
<p>I plan to throw light on the relationship between these 2, from a web developer’s point of view.</p>
<h2>What is ‘SEMANTICS’?</h2>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/semantics.jpg"><img class="alignright size-full wp-image-15963" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/semantics.jpg" alt="" width="150" height="150" /></a>Wikipedia, says <em>- ‘<strong>Semantics</strong> (from Greek  &#8211; semantikos) is the study of meaning, usually in language’. </em>Relating this to the internet, semantics is the study of meaning of data, ie, it is the study of the concept which makes a machine, understand what type of data it is dealing with (as far as web is concerned, the ‘machine’ can be the browser, or any program / code, that deals with the data).</p>
<p>Example: A page may contain, a group of data, which are related to each other, like the steps to be taken to accomplish a task. There may be a tabular data, which comprehends the details of a product, its configurations and price details. There may be a date on which a particular document was created … and the list goes on and on.  In order to make those content / data meaningful to the machines, we need to follow some global guidelines, while creating them,  which entitles the data to be a particular type or the other. Streamlining the data like this would make it really easier to make the data ‘machine readable’ and this is the first step towards efficient data segregation and relation.</p>
<p>For instance, how would it feel like, if you are able to aggregate all the data available about a new gadget that you are planning to buy – the pricing, reviews, configuration, features  everything displayed in a single page, fetched from millions of machine readable data available over the web !</p>
<p>This exactly is the future of web, and the search god ‘Google’, is already relying on such search features, which would make them ‘uber-god’ of the search engine world!</p>
<h2>How is HTML related to ‘Semantics’?</h2>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/semanticnhtmllink.jpg"><img class="alignleft size-full wp-image-15964" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/semanticnhtmllink.jpg" alt="" width="150" height="150" /></a>Since, a browser is the primary interface enabling the user to get connected to the internet (computer screen, mobile screen, TV, Projector are all different medias, but ultimately, all these needs a browser to download the page locally and view the contents), and there is only one way, with which content can be displayed in a browser – which is the ‘HTML’ way. So, HTML holds the major stake, in determining the way, data has to be displayed on a page, and the ‘<a href="http://www.quackit.com/html/tags/">tags</a>’ used in rendering the output as HTML, to a browser determines the meaningfulness of the data contained. This is important, because a particular data/content can be rendered, using more than one HTML tag.</p>
<p>The page/content is said to be meaningfully rendered, or said to be ‘semantically correct’, if those are rendered using tags which represent the correct meaning of the data. Eg.  A date rendered in a  tag, a quote rendered in a <q> tag, a label rendered in a <label> tag etcetra.</label></q></p>
<h2>Find below, the ‘semantics’ of a few HTML tags</h2>
<p>(courtesy: <a href="http://www.htmlplayground.com/"><em>htmlplayground</em></a>)</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="169" valign="top">h1</td>
<td width="469" valign="top">Normally the main header of the page. An ideal page should have a   single h1 tag in it. Some constructive debate here <a href="http://www.smileycat.com/miaow/archives/000784.php">link1</a>, <a href="http://www.webmasterworld.com/google/3773892.htm">link2</a>. Headers   from H1 till H6 should be used hierarchically to denote the importance of the   header in the context.</td>
</tr>
<tr>
<td width="169" valign="top">abbr</td>
<td width="469" valign="top">Indicates an abbreviated form, like &#8220;Inc.&#8221;,   &#8220;etc.&#8221;. By marking up abbreviations you can give useful information   to browsers, spell checkers, translation systems and search-engine indexers.</td>
</tr>
<tr>
<td width="169" valign="top">address</td>
<td width="469" valign="top">The</p>
<address> tag defines the start of an address. You should   use it to define addresses, signatures, or authorships of documents. The   address usually renders in italic. Most browsers will add a line break before   and after the address element, but line breaks inside the text you have to   insert yourself.</address>
</td>
</tr>
<tr>
<td width="169" valign="top">sup</td>
<td width="469" valign="top">Defines superscript text.</td>
</tr>
<tr>
<td width="169" valign="top">div</td>
<td width="469" valign="top">Defines a division/section in a document. Browsers usually place a   line break before and after the div element. Use the &lt;div&gt; tag to group   block-elements to format them with styles.</td>
</tr>
<tr>
<td width="169" valign="top">kbd</td>
<td width="469" valign="top">Defines keyboard text. Phrase element. It is possible to achieve a   much richer effect using style sheets.</td>
</tr>
<tr>
<td width="169" valign="top">legend</td>
<td width="469" valign="top">Defines a caption for a fieldset.</td>
</tr>
<tr>
<td width="169" valign="top">big</td>
<td width="469" valign="top">Renders as bigger text. Not deprecated, but it is better to achieve   richer effects using style sheets.</td>
</tr>
<tr>
<td width="169" valign="top">P</td>
<td width="469" valign="top">Defines a paragraph.</td>
</tr>
<tr>
<td width="169" valign="top">button</td>
<td width="469" valign="top">Defines a push button. Inside a button element you can put content,   like text or images. This is the difference between this element and buttons   created with the input element.</td>
</tr>
<tr>
<td width="169" valign="top">ol</td>
<td width="469" valign="top">Defines the start of an ordered list.</td>
</tr>
<tr>
<td width="169" valign="top">cite</td>
<td width="469" valign="top">Defines a citation. Phrase element.It is possible to achieve a much   richer effect using style sheets.</td>
</tr>
<tr>
<td width="169" valign="top">em</td>
<td width="469" valign="top">Renders as emphasized text. Phrase element.It is possible to achieve   a much richer effect using style sheets.</td>
</tr>
<tr>
<td width="169" valign="top">pre</td>
<td width="469" valign="top">The pre element defines preformatted text. The text enclosed in the   pre element usually preserves spaces and line breaks. The text renders in a   fixed-pitch font. It is worth noting that while &lt;xmp&gt; is deprecated,   the &lt;pre&gt; tag does not perform all of the functions of &lt;xmp&gt;:   &lt;pre&gt;&lt;b&gt;Hello&lt;/b&gt;&lt;/pre&gt; displays Hello   &lt;xmp&gt;&lt;b&gt;Hello&lt;/b&gt;&lt;/xmp&gt; displays   &lt;b&gt;Hello&lt;/b&gt;</td>
</tr>
</tbody>
</table>
<h2>Why Semantics?</h2>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/need4sematnics.jpg"><img class="alignright size-full wp-image-15965" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/need4sematnics.jpg" alt="" width="150" height="150" /></a>The actual advantages of sticking to semantically correct HTML are numerous. Here are a few of them …</p>
<h3>Search Engine Optimization</h3>
<p>With the advent of web, information is money, and getting the right information which you look for, at the right time is more important, since no body wants to waste time searching for an information too long. Here comes the era of search engines, and the key here is to make the data / content in your piece of land on the web, appear in a decent position of SERP (Search Engine Result Pages). Using semantically correct code means that your page is easy to read for the machines, and ‘search engine robots’ are nothing else, but machines / programs of search engines J. So, semantically correctly coded pages stands a better chance to appear on top of SERPs.</p>
<h3>Scalability / Flexibility</h3>
<p>Updating the pages, which are semantically well coded, is a pleasure! Since each sections are coded using the relevant tags, a change in style for the element can be done in the updation of CSS selector for that particular tag and markup level changes can also be done seamlessly.</p>
<h3>Accessibility</h3>
<p>There are visually impaired users using the internet, and they might use a screen reader to read out the contents aloud. These screen readers are programs (machines in our terminology J)which reads the content of the page, by trying to understand the meaning of the data represented.</p>
<p>There is not a better way to make things easier for these programs to understand the content of the page, than  using a semantically well coded page ?</p>
<h3>Cleaner and shorter code</h3>
<p>Semantically correct page means, a clean and crisper code, which also means lightweight stuff for the browser to load !</p>
<h2>‘The pursuit of Semantic Wellness’ – some practical insights</h2>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/semanticwellness.jpg"><img class="alignleft size-full wp-image-15966" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/semanticwellness.jpg" alt="" width="150" height="150" /></a>The pursuit to achieve ‘semantic wellness’, never ends! Every time you code a page, and assume it to be the semantically perfect markup ever, there comes another better way to represent the same in a more correct way. It is all practice, experience and a thorough knowledge of the HTML specifications, which would make a coder compliant to semantics. Here are some insights that I have gained over a period of time as a UX evangelist and Front end engineer, that would help you to be successful in your pursuit of ‘semantic wellness’ :)</p>
<h3>Avoid ‘DIV syndrome’</h3>
<p>Separating content and presentation using a DIV based layout with CSS, doesn’t mean that DIV is the only tag that you should be using. Avoid ‘<a href="http://en.wiktionary.org/wiki/divitis">DIVITIS</a>’ by carefully choosing the tags for coding your page. This is the first step for ‘ semantic wellness ’.  A great resource to start with is ‘<a href="http://www.htmlplayground.com/">htmlplayground</a>’</p>
<h3>It really is a pain, but learn to embrace it</h3>
<p>Fast tracking your HTML coding can save you time and you may be able to earn more by billing more to the client. But ‘Better things come at a cost’ ! If you want to be a semantically correct coder, be ready to bear the brunt of the excess hours and frustrating cross-browser issues and fixes. But remember, all those hardships are worth it, and the more you learn to embrace it, the more valuable you would be as a web standard evangelist.</p>
<h3>Know the structure of the content/information</h3>
<p>For knowing which tags to use where, it is extremely important to understand the type of content, in an Information Architecture level.</p>
<p>For eg .</p>
<ul>
<li>The main navigation of a page, are a list of items that have something in common. ie, they all belong to the logical set called, main navigation. Here the ideal HTML tag candidate is unordered list (ul).</li>
<li>A step wizard, where there are a number of steps required to accomplish a task, will need to have the chronological order of the step as a very important factor. Here the ideal HTML tag candidate is ordered list (ol)</li>
<li>A list of posts displayed in a page are nothing but unordered lists (ul)</li>
<li>A glossary with alphabetical segregation is a couplet of, a term and a definition. Here the ideal HTML tag candidate is definition lists (dl)</li>
</ul>
<h4>Some related resources</h4>
<ul>
<li><a href="http://bit.ly/azg8c8">Writing  semantic markup</a></li>
<li><a href="http://bit.ly/c3nPdm">Guide to semantic mark-up</a></li>
</ul>
<h3>Watch out your Class names and ID names</h3>
<p>Semantic wellness does not mainly fall under well written HTML tags. But it spills over to the CSS also. I would easily find out a semantic compliant coder, by scanning through the naming conventions of the classes and IDs of the CSS file !</p>
<p>Always avoid presentational names for classes or IDs, and it would yell out to the world about your attitude towards semantics. <a href="http://sixrevisions.com/css/css-tips/css-tip-2-structural-naming-convention-in-css/">Read this</a> for more insights on structural naming convention.</p>
<h2>HTML5 – The big leap towards ‘Semantic wellness’</h2>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/html5.jpg"><img class="alignright size-full wp-image-15967" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/html5.jpg" alt="" width="150" height="150" /></a>As I told in the introduction of this article, the coming era of the web will be that of Semantic web, and the giants of web have already started embracing this in a very big way. This latest edition to the family HTML is going to be biggest leap of web towards a semantically correct place. With a lot of groundbreaking proprietary tags implemented, and the dependency of various third-party tools being dropped, this version of HTML is truly going to lead the bandwagon towards the semantic web.</p>
<h3>Here is a brief account on the new tags that are implemented in HTML5<br />
<strong><br />
</strong></h3>
<p><strong> &lt;header&gt;&lt;/header&gt;</strong><br />
The <code>header</code> of a <code>'section'</code>, typically a headline or grouping of headlines, but may also contain supplemental information about the section.</p>
<p><strong>&lt;footer&gt;&lt;/footer&gt;<br />
</strong>This tag logically represents the footer section, with the copyright and other footer information including the footer links and all</p>
<p><strong>&lt;nav&gt;&lt;/nav&gt;<br />
</strong>Represents the navigation of the page, where normally there would be a list of links which leads to respetive contents/pages. This tag should be in the same level as header, footer and the main section tags used in a particular page</p>
<p><strong>&lt;article&gt;&lt;/article&gt;<br />
</strong>An article could represent content that logically is equivalent to an entry of a blog, an article or some other content from an external source</p>
<p><strong>&lt;aside&gt;&lt;/aside&gt;<br />
</strong>An aside indicates content that is tangentially related to the content around it.</p>
<p><strong>&lt;audio&gt;&lt;/audio&gt;<br />
</strong>Defines sound, like music or audio streams</p>
<p><strong>&lt;video&gt;&lt;/video&gt;<br />
</strong>Defines video, like video clip or streaming video</p>
<h3>The following is a visual representation of the architecture of HTML tags in a typical web page.</h3>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/html5struture.jpg"><img class="size-full wp-image-15961 alignnone" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/html5struture.jpg" alt="" width="346" height="262" /></a></p>
<h3>Resources on HTML5</h3>
<ul>
<li><a href="http://html5readiness.com/">HTML5 Readiness</a></li>
<li><a href="http://caniuse.com/">Caniuse.com</a></li>
<li><a href="http://heideri.ch/jso/">HTML5 Security Cheatsheet</a></li>
<li><a href="http://dev.opera.com/articles/view/accessible-html5-video-with-javascripted-captions/">Accessible HTML5 Video</a></li>
<li><a href="http://html5test.com/">Test your browser support for HTML5</a></li>
</ul>
<h2>Resource to help you out in ‘The Pursuit of Semantic Wellness’</h2>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/pursuit1.jpg"><img class="size-full wp-image-15973 alignleft" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/05/pursuit1.jpg" alt="" width="150" height="150" /></a></p>
<p style="text-align: left;">Semantics is a vast ocean by itself &#8230; and what i have covered here is its relation with the HTML. This article intends to throw on the aspects of semantics, when it comes to coding an HTML page, and is aimed at those aspiring front end engineers and web standards evangelists, to help them out in bringing out the best. Sharing few of the resources that I have gathered over years, which may help you out to become a semantic rockstar :)</p>
<ul>
<li><a href="http://bit.ly/9S8Bkc">semantic-cod</a><a href="http://bit.ly/9S8Bkc">e-what-why-how</a></li>
<li><a href="http://bit.ly/aWIX6O">Div Mania</a></li>
<li><a href="http://bit.ly/aAYwf7">Tying web 3.0 </a></li>
<li><a href="http://bit.ly/bMD6rH">HTML Vs B</a><a href="http://bit.ly/bMD6rH">ody Element</a></li>
<li><a href="http://bit.ly/cPmj2r">Preparing for HTML5</a></li>
<li><a href="http://bit.ly/an339Q">W3C Semantic Web FAQ</a></li>
</ul>
<p>Don&#8217;t forget to share your input with us via comments section. Thanks for reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/design/html-and-semantics-conjoined-twins-of-the-future-web/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Building Real-Time Form Validation Using jQuery</title>
		<link>http://www.1stwebdesigner.com/tutorials/building-real-time-form-validation-using-jquery/</link>
		<comments>http://www.1stwebdesigner.com/tutorials/building-real-time-form-validation-using-jquery/#comments</comments>
		<pubDate>Mon, 03 May 2010 10:00:09 +0000</pubDate>
		<dc:creator>Michal Kozak</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=12546</guid>
		<description><![CDATA[Client-side validation is something every web form should have, no doubts about that. While server-side validation does its job, it certainly lacks good user experience. What is so great about client-side validation then? Not only is it useful to the user because it makes the process of filling out the form a lot quicker and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.1stwebdesigner.com/tutorials/building-real-time-form-validation-using-jquery/"><img class="alignleft" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jquery-real-time-form-validation.jpg" alt="Building Real-Time Form Validation Using jQuery" width="150" height="150" /></a>Client-side validation is something every web form should have, no doubts about that. While server-side validation does its job, it certainly lacks good user experience. What is so great about client-side validation then?</p>
<p>Not only is it useful to the user because it makes the  process of filling out the form a lot quicker and a lot less painful, but it also shows that you actually care about them. For the user there&#8217;s nothing better than knowing right away if they&#8217;re doing it correctly.</p>
<p>In this tutorial we&#8217;re going to learn how to build real-time form validation using jQuery. If you&#8217;d like to see what you&#8217;ll be building, you can watch the short video intro or hit the &#8220;Live Demo&#8221; button and check it out.</p>
<p><span id="more-12546"></span><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="345" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="flashvars" value="i=64637" /><param name="allowFullScreen" value="true" /><param name="src" value="http://screenr.com/Content/assets/screenr_1116090935.swf" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="345" src="http://screenr.com/Content/assets/screenr_1116090935.swf" allowfullscreen="true" flashvars="i=64637"></embed></object></p>
<div><a href="http://dl.dropbox.com/u/1715120/demos/real-time-form-validation-using-jquery/index.html"><img src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/live-demo-button.png" alt="Check out Live Demo for Real-Time jQuery Form Validation" width="570" height="50" /></a></div>
<h2>Table of Contents</h2>
<ol>
<li><a href="#part1">How Will We Achieve That?</a></li>
<li><a href="#part2">Project Structure</a></li>
<li><a href="#part3">Coding the HTML</a>
<ul>
<li><a href="#part3.1">Some Basic HTML and Importing jQuery + Validation Script</a></li>
<li><a href="#part3.2">The Form, Splitted Into Three Sections</a></li>
<li><a href="#part3.3">Adding Fields + Submit Button</a></li>
</ul>
</li>
<li><a href="#part4">Spicing It Up With CSS</a></li>
<li><a href="#part5">All The Fun: jQuery Magic</a>
<ul>
<li><a href="#part5.1">Planning</a></li>
<li><a href="#part5.2">What Do We Need?</a></li>
<li><a href="#part5.3">Our Script &#8220;Packaging&#8221;</a></li>
<li><a href="#part5.4">Validating User&#8217;s Name</a></li>
<li><a href="#part5.5">Validating User&#8217;s Date of Birth</a></li>
<li><a href="#part5.6">Validating User&#8217;s Gender</a></li>
<li><a href="#part5.7">Validating Vehicles Owned by User</a></li>
<li><a href="#part5.8">Validating User&#8217;s Email Address</a></li>
<li><a href="#part5.9">Validating User&#8217;s About Info</a></li>
<li><a href="#part5.10">Final <code>sendIt</code> Method</a></li>
<li><a href="#part5.11">Managing User&#8217;s Submit Action</a></li>
</ul>
</li>
<li><a href="#part6">Final Product</a></li>
<li><a href="#part7">After Word</a></li>
</ol>
<h2 id="part1">How Will We Achieve That?</h2>
<p>Now, there are actually many ways to do that; here are the most common:</p>
<ol>
<li>We could put <code>&lt;/span&gt;</code> (which will be holding validation info) next to our form field and give it an <code>ID</code> so we can easily access its content later</li>
<li> We could wrap every field in <code>&lt;/p&gt;</code> with applied <code>ID</code>, and put <code>&lt;/span&gt;</code> (which will be holding validation info) inside it, so we can easily access its content, through that <code>&lt;/p&gt;</code>&#8216;s child-span</li>
<li> We could wrap every field in <code>&lt;/p&gt;</code> with applied <code>ID</code>, and inject <code>&lt;/span&gt;</code> with validation info to it</li>
</ol>
<p>It will all work, but neither is the optimal way. Why? Because there&#8217;s too much messing with your HTML code and you&#8217;ll end up with bunch of needless tags that are required by your validation script, but which your form doesn&#8217;t really need.</p>
<p>It&#8217;s clearly not the way to go, so instead we&#8217;re going to do this the way I do it myself. In my opinion it&#8217;s the best solution, although it&#8217;s not very common; I honestly have never came across this method, I&#8217;ve never seen it used by someone. But if <em>you</em> have, please let me know in the comments.</p>
<p>OK, so what are we going to do?</p>
<ol>
<li>We&#8217;re going to write simplest form possible, nice and clean, no unnecessary tags whatsoever</li>
<li>As the user fills out particular field, we&#8217;re goinng to validate it on the fly and:
<ul>
<li>grab its position in the window (top and left)</li>
<li>grab its width</li>
<li>add width and the left offset (from the field&#8217;s position) together so we know where the field ends</li>
<li>put validation info into <code>&lt;/div&gt;</code> with applied <code>ID</code>, inject it to the document, position it absolutely on the spot where the field ends, and manipulate its <code>class</code> as needed (for example <code>.correct</code> or <code>.incorrect</code>)</li>
</ul>
</li>
</ol>
<p>That way we keep our HTML code nice and clean.</p>
<p><strong><em>Note</em></strong>: It&#8217;s vital to <em>always</em> provide server-side validation as well (for users with turned off JavaScript).</p>
<h2 id="part2">Project Structure</h2>
<p>We are going to need three files:</p>
<ul>
<li>index.html</li>
<li>style.css</li>
<li>validation.js</li>
</ul>
<p>I&#8217;m gonna go roughly through the HTML coding, provide you with all needed CSS &#8211; and then focus mostly on our jQuery script, which is the most important thing and what we&#8217;re hoping to learn today.</p>
<h2 id="part3">Coding the HTML</h2>
<h4 id="part3.1">Step 1: Some Basic HTML and Importing jQuery + Validation Script</h4>
<p>First, make <em>index.html</em> file and put some basic code there; you can see that we imported jQuery at the bottom, along with our <em>validation.js</em> file, which will contain our validation script:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Real-Time Form Validation Using jQuery&lt;/title&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id=&quot;content&quot;&gt;

&lt;/div&gt;&lt;!-- content --&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;validate.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h4 id="part3.2">Step 2: The Form, Splitted Into Three Sections</h4>
<p>We&#8217;re going to split the form into <em>three sections</em> using <code>&lt;/fieldset&gt;</code>, and <code>&lt;/label&gt;</code> for each section headline:</p>
<ol>
<li>Personal Info (user name, date of birth, gender, vehicles)</li>
<li>Email (user&#8217;s email adress)</li>
<li>About (little info about the user)</li>
</ol>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Real-Time Form Validation Using jQuery&lt;/title&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id=&quot;content&quot;&gt;
&lt;form id=&quot;jform&quot; action=&quot;http://1stwebdesigner.com&quot; method=&quot;post&quot;&gt;
	&lt;fieldset&gt;
		&lt;legend&gt;Personal Info&lt;/legend&gt;
	&lt;/fieldset&gt;

	&lt;fieldset&gt;
		&lt;legend&gt;Email&lt;/legend&gt;
	&lt;/fieldset&gt;

	&lt;fieldset&gt;
		&lt;legend&gt;About You&lt;/legend&gt;
	&lt;/fieldset&gt;
&lt;/form&gt;
&lt;/div&gt;&lt;!-- content --&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;validate.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h4 id="part3.3">Step 3: Adding Fields + Submit Button</h4>
<p>Great, now it&#8217;s time to finally add some fields to our form. For this tutorial we&#8217;re going to use several different fields:</p>
<ul>
<li>three text <code>input</code>s: for user&#8217;s full name, date of birth and email adress</li>
<li><code>radio</code> buttons for user&#8217;s gender</li>
<li><code>checkbox</code>es for vehicles owned by the user</li>
<li><code>textarea</code> for little info about the user</li>
<li><code>button</code> for submit button</li>
</ul>
<p>We&#8217;re going to wrap every set (<code>label</code> + field) in <code>&lt;/p&gt;</code> to keep them separated and display them as blocks.</p>
<p>Your final <em>index.html</em> file should look like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;Real-Time Form Validation Using jQuery&lt;/title&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id=&quot;content&quot;&gt;
	&lt;form id=&quot;jform&quot; action=&quot;http://1stwebdesigner.com&quot; method=&quot;post&quot;&gt;
		&lt;fieldset&gt;
			&lt;legend&gt;Personal Info&lt;/legend&gt;
			&lt;p&gt;
				&lt;label for=&quot;fullname&quot; class=&quot;block&quot;&gt;Full name:&lt;/label&gt;
				&lt;input type=&quot;text&quot; name=&quot;fullname&quot; id=&quot;fullname&quot; /&gt;
			&lt;/p&gt;
			&lt;p&gt;
				&lt;label for=&quot;birthday&quot; class=&quot;block&quot;&gt;Day of birth &lt;small&gt;(dd-mm-yyyy)&lt;/small&gt;:&lt;/label&gt;
				&lt;input type=&quot;text&quot; name=&quot;birthday&quot; id=&quot;birthday&quot; /&gt;
			&lt;/p&gt;
			&lt;p&gt;
				&lt;label class=&quot;block&quot;&gt;I am:&lt;/label&gt;
				&lt;input type=&quot;radio&quot; name=&quot;gender&quot; id=&quot;man&quot; value=&quot;man&quot; /&gt; &lt;label for=&quot;man&quot;&gt;Man&lt;/label&gt;
				&lt;input type=&quot;radio&quot; name=&quot;gender&quot; id=&quot;woman&quot; value=&quot;woman&quot; /&gt; &lt;label for=&quot;woman&quot;&gt;Woman&lt;/label&gt;
			&lt;/p&gt;
			&lt;p&gt;
				&lt;label class=&quot;block&quot;&gt;I own:&lt;/label&gt;
				&lt;input type=&quot;checkbox&quot; name=&quot;vehicle&quot; id=&quot;car&quot; /&gt; &lt;label for=&quot;car&quot;&gt;car&lt;/label&gt;
				&lt;input type=&quot;checkbox&quot; name=&quot;vehicle&quot; id=&quot;airplane&quot; /&gt; &lt;label for=&quot;airplane&quot;&gt;airplane&lt;/label&gt;
				&lt;input type=&quot;checkbox&quot; name=&quot;vehicle&quot; id=&quot;bicycle&quot; /&gt; &lt;label for=&quot;bicycle&quot;&gt;bicycle&lt;/label&gt;
				&lt;input type=&quot;checkbox&quot; name=&quot;vehicle&quot; id=&quot;ship&quot; /&gt; &lt;label for=&quot;ship&quot;&gt;ship&lt;/label&gt;
			&lt;/p&gt;
		&lt;/fieldset&gt;

		&lt;fieldset&gt;
			&lt;legend&gt;Email&lt;/legend&gt;
			&lt;p&gt;
				&lt;label for=&quot;email&quot; class=&quot;block&quot;&gt;Email &lt;small&gt;(mickey@mou.se)&lt;/small&gt;:&lt;/label&gt;
				&lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; /&gt;
			&lt;/p&gt;
		&lt;/fieldset&gt;

		&lt;fieldset&gt;
			&lt;legend&gt;About You&lt;/legend&gt;
			&lt;p&gt;
				&lt;label for=&quot;about&quot; class=&quot;block&quot;&gt;Tell us a little bit about yourself:&lt;/label&gt;
				&lt;textarea id=&quot;about&quot; cols=&quot;50&quot; rows=&quot;10&quot;&gt;&lt;/textarea&gt;
			&lt;/p&gt;
		&lt;/fieldset&gt;
		&lt;p&gt;
			&lt;button type=&quot;submit&quot; id=&quot;send&quot;&gt;submit&lt;/button&gt;
		&lt;/p&gt;
	&lt;/form&gt;
&lt;/div&gt;&lt;!-- content --&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;validate.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>It may look a bit messy, but it&#8217;s because of the WP&#8217;s syntax highlighting plugin. It&#8217;s actually really clean, and that&#8217;s what we wanted to achieve afterall. Check it: save the above code as your <em>index.html</em> file, open it in your browser and look at the source code. Now it looks clean, isn&#8217;t it?</p>
<h2 id="part4">Spicing It Up With CSS</h2>
<p>Since CSS styling is not our main focus in this tutorial, I&#8217;m not gonna go over this, but simply provide you with the CSS you&#8217;re going to need for this to work.</p>
<p>Create <em>style.css</em> file, put inside all the code from below and that&#8217;s it! Now everything should look sweet.</p>
<pre class="brush: css; title: ; notranslate">
body {
	background: #efefef;
	margin: 0;
	padding: 0;
	border: none;
	text-align: center;
	font: normal 13px Georgia, &quot;Times New Roman&quot;, Times, serif;
	color: #222;
}

#content {
	width: 500px;
	margin: 0 auto;
	margin-bottom: 25px;
	padding: 0;
	text-align: left;
}

fieldset {
	margin-top: 25px;
	padding: 15px;
	border: 1px solid #d1d1d1;
	-webkit-border-radius: 7px;
	-moz-border-radius: 7px;
	border-radius: 7px;

}

fieldset legend {
	font: normal 30px Verdana, Arial, Helvetica, sans-serif;
	text-shadow: 0 1px 1px #fff;
	letter-spacing: -1px;
	color: #273953;
}

input, textarea {
	padding: 3px;
}

label {
	cursor: pointer;
}

.block {
	display: block;
}

small {
	letter-spacing: 1px;
	font-size: 11px;
	font-style: italic;
	color: #9e9e9e;
}

.info {
	text-align: left;
	padding: 5px;
	font-size: 11px;
	color: #fff;
	position: absolute;
	display: none;
	-webkit-border-radius: 5px;
	-moz-border-radius: 5px;
	border-radius: 5px;
	-webkit-box-shadow: -1px 1px 2px #a9a9a9;
	-moz-box-shadow: -1px 1px 2px #a9a9a9;
	box-shadow: -1px 1px 2px #a9a9a9;
}

.error {
	background: #f60000;
	border: 3px solid #d50000;

}

.correct {
	background: #56d800;
	border: 3px solid #008000;
}

.wrong {
	font-weight: bold;
	color: #e90000;
}

.normal {
	font-weight: normal;
	color: #222;
}

#send {
	background: #3f5a81;
	width: 100%;
	border: 5px solid #0F1620;
	font: bold 30px Verdana, sans-serif;
	color: #fafafa;
	text-shadow: 1px 1px 1px #0F1620;
	-webkit-border-radius: 7px;
	-moz-border-radius: 7px;
	border-radius: 7px;
}

#send:hover {
	background: #4d76b1;
	border: 5px solid #253750;
	color: #fff;
}

#send:active {
	text-indent: -10px;
}
</pre>
<h2 id="part5">All The Fun: jQuery Magic</h2>
<p>This is the most interesting and engaging part. First we need to do some thinking and describe our key points.</p>
<h4 id="part5.1">Step 1: Planning</h4>
<p>We have to ask ourselves three questions before we can go on:</p>
<ol>
<li>What do we need the script to do?</li>
<li>How do we want it to do this?</li>
<li>How do we achieve that?</li>
</ol>
<p>It&#8217;s obvious we want the script to validate our form. But how?</p>
<ul>
<li>we want to be able to validate it both in real-time (when user is filling it out) and on the form submit</li>
<li>therefore we need to make a &#8220;pack&#8221; of functions responsible for each of its fields, so we can call them:
<ul>
<li>individually, when the user is filling out particular field</li>
<li>all at once, on the form submit</li>
</ul>
</li>
</ul>
<p>To reduce our global footpring, we&#8217;re going to use JavaScript <code>object</code> for that.</p>
<h4 id="part5.2">Step: 2: What Do We Need?</h4>
<p>JS object, in our case it will be:</p>
<ul>
<li><code>jVal</code></li>
</ul>
<p>Methods of that object for each of the form fields, validating that particular field:</p>
<ul>
<li><code>jVal.fullName</code></li>
<li><code>jVal.birthDate</code></li>
<li><code>jVal.gender</code></li>
<li><code>jVal.vehicle</code></li>
<li><code>jVal.email</code></li>
<li><code>jVal.about</code></li>
</ul>
<p>Variable which will hold the status of error occuring:</p>
<ul>
<li><code>jVal.errors</code></li>
</ul>
<p>And method that will be called as the last one; it will check if there were any errors and submit the form if not. If some errors occurred, it will take the user to the beginning of the form, so they can fill it out again.</p>
<ul>
<li><code>jVal.sendIt</code></li>
</ul>
<p>Now we can finally start building our validation script. When finish our first validation method, then it will be much easier and faster, as we can reuse it for other methods, only applying some changes. Let&#8217;s crack into it!</p>
<h4 id="part5.3">Step 3: Our Script &#8220;Packaging&#8221;</h4>
<p>The start is really simple, almost everything will go inside this code:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
	jVal = {

	};
});
</pre>
<h4 id="part5.4">Step 4: Validating User&#8217;s Name</h4>
<p>Our first method will handle user&#8217;s name. Put it inside our <code>jVal</code> object, like this:</p>
<pre class="brush: jscript; title: ; notranslate">
var jVal = {
	'fullName' : function() {

	}
};
</pre>
<p>Now let&#8217;s put some first lines of code inside our method. Just paste it, and then I will explain what the code &#8220;says&#8221;:</p>
<pre class="brush: jscript; title: ; notranslate">
$('body').append('&lt;div id=&quot;nameInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

var nameInfo = $('#nameInfo');
var ele = $('#fullname');
var pos = ele.offset();
</pre>
<ul>
<li><em>Line 1:</em> We&#8217;re injecting <code>&lt;/div&gt;</code> to the document. <code>Class</code> &#8220;info&#8221; gives it some styling (defined in our CSS file) and also make it invisible by setting <code>display</code> to &#8220;none&#8221; &#8211; so it&#8217;s there, but we don&#8217;t see it yet. As for the <code>ID</code>, it&#8217;s for easy &#8220;grabbing&#8221; and manipulating, since it will be positioned absolutely in the document. This <code>&lt;/div&gt;</code> will contain our validation info that will be showed to the user, so they know if they filled out the field correctly.</li>
<li><em>Line 3:</em> We&#8217;re assigning our <code>&lt;/div&gt;</code> to the variable <code>nameInfo</code>, because we&#8217;ll be using it couple times more.</li>
<li><em>Line 4:</em> We&#8217;re assigning our form field with <code>ID</code> &#8220;fullname&#8221; to the variable <code>ele</code>. The same reason as above, we will use it several times later.</li>
<li>jQuery function <code>offset()</code> returns current position of an element relative to the document.  It returns an object containing the properties <em>top</em> and <em>left</em>. We used this function on our <code>ele</code> (which is actually form input with <code>ID</code> &#8220;fullname&#8221;), so it will return position of that element, which we assign to the variable <code>pos</code>.</li>
</ul>
<p>Great, so far so good. It&#8217;s time to add some few more lines:</p>
<pre class="brush: jscript; title: ; notranslate">
nameInfo.css({
	top: pos.top-3,
	left: pos.left+ele.width()+15
});
</pre>
<ul>
<li><em>Line 2:</em> We start to operate on <code>nameInfo</code>&#8216;s CSS <code>top</code> property. Remember, our variable <code>pos</code> holds now the position of our form input with <code>ID</code> &#8220;fullname&#8221; in the document. We access its <em>top</em> value by simply joining <code>pos</code> with the word <em>top</em> using period <code> . </code>. Then we decrement that by <code>3</code> and assign it to the CSS <code>top</code> property of our <code>nameInfo</code> element.</li>
<li><em>Line 3:</em> We start to operate on <code>nameInfo</code>&#8216;s CSS <code>left</code> property. We access <em>left</em> value of our &#8220;Full name&#8221; input&#8217;s position, increase it by its width (we grab that from calling jQuery function <code>width()</code> on our <code>ele</code> element) and increase it by <code>15</code>. The result is assigned to the CSS <code>left</code> property of our <code>nameInfo</code> element.</li>
</ul>
<p>We&#8217;re doing really great, we just acomplished 50% of <code>fullName</code>, our first validating method. It&#8217;s time to actually check if the user filled our &#8220;Full name&#8221; field correctly or not, and take appropriate action:</p>
<pre class="brush: jscript; title: ; notranslate">
if(ele.val().length &lt; 6) {
	jVal.errors = true;
		nameInfo.removeClass('correct').addClass('error').html('&amp;larr; at least 6 characters').show();
		ele.removeClass('normal').addClass('wrong');
} else {
		nameInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
		ele.removeClass('wrong').addClass('normal');
}
</pre>
<p>Lot of weird crap, huh? Don&#8217;t worry, it&#8217;s not so scary as it may look:</p>
<ul>
<li><em>Line 1:</em> We&#8217;re checking if the name that user typed in is shorter than <code>6</code> characters.</li>
<li><em>Line 2:</em> We set our object&#8217;s variable <code>jVal.errors</code> to <code>true</code>, as we just got our first error (user&#8217;s name is too short). We&#8217;re going to use it later.</li>
<li><em>Line 3:</em> We start to operate on our <code>nameInfo</code> element (which is the <code>&lt;/div&gt;</code> we&#8217;re gonna display validation info in). First we remove the <code>class</code> &#8220;correct&#8221;; it may be applied to our <code>nameInfo</code> element from previous validation (if it was performed). Then we apply the <code>class</code> &#8220;error&#8221; to it. Next, we put content to our <code>nameInfo</code> element, it&#8217;s the information that the name should be at least 6 characters long. And finally we our alert-box visible to the user.</li>
<li><em>Line 4:</em> We start to operate on our <code>ele</code> element (which is our form &#8220;Full name&#8221; input). First we remove <code>class</code> &#8220;normal&#8221;, which may be there from previous validation, then we apply <code>class</code> &#8220;wrong&#8221; to it.</li>
<li><em>Line 5:</em> If the name user typed in was long enough, then&#8230;</li>
<li><em>Line 6:</em> We start to operate on our <code>nameInfo</code> element. We remove <code>class</code> &#8220;error&#8221; if it&#8217;s there, and apply <code>class</code> &#8220;correct&#8221;. We put <code>√</code> inside to let the user know it&#8217;s all good. We show the alert-box (if it wasn&#8217;t visible before).</li>
<li><em>Line 7:</em> We start to operate on our <code>ele</code> element. We remove <code>class</code> &#8220;wrong&#8221; if it&#8217;s there, and apply <code>class</code> &#8220;normal&#8221;.</li>
</ul>
<p>Well done! This is our first validation method. Now it&#8217;s time to test it, but before we can do that, we need to write few more lines of code.</p>
<p>We need to make sure, that our <code>fullName</code> method will be called when the user finished filling out the &#8220;Full name&#8221; field. To achieve that, we need to bind our method to certain user action. There are two great jQuery functions that would serve that purpose well: <code>blur()</code> and <code>change()</code>. We are going to use <code>change()</code>.</p>
<p>Paste this code <em>below</em> the whole <code>jVal</code> object:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#fullname').change(jVal.fullName);
</pre>
<p>What it does in human words: if the user changes value of the &#8220;Full name&#8221; field and then leaves (e.g. to fill out another field), our <code>fullName</code> method is fired up, to validate &#8220;Full name&#8221; field.</p>
<p>Right now you should have one fully working validation method, so test it. Your whole <em>validate.js</em> file should like like this:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){

	var jVal = {
		'fullName' : function() {

			$('body').append('&lt;div id=&quot;nameInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

			var nameInfo = $('#nameInfo');
			var ele = $('#fullname');
			var pos = ele.offset();

			nameInfo.css({
				top: pos.top-3,
				left: pos.left+ele.width()+15
			});

			if(ele.val().length &lt; 6) {
				jVal.errors = true;
					nameInfo.removeClass('correct').addClass('error').html('&amp;larr; at least 6 characters').show();
					ele.removeClass('normal').addClass('wrong');
			} else {
					nameInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
					ele.removeClass('wrong').addClass('normal');
			}
		}
	};

	// bind jVal.fullName function to &quot;Full name&quot; form field
	$('#fullname').change(jVal.fullName);

});
</pre>
<h4 id="part5.5">Step 5: Validating User&#8217;s Date of Birth</h4>
<p>Starting from now, it will all get easier. Our validation methods are in 90% the same, so all you have to do is copy our <code>fullName</code> method, and only apply some changes</p>
<p>Great, so now just copy whole <code>fullName</code> method, paste it below and rename it to <code>birthDate</code>. The changes we need to make are:</p>
<ul>
<li>all <code>nameInfo</code> occurences have to become <code>birthInfo</code></li>
<li>instead of <code>#fullname</code>, assign <code>#birthday</code> element to variable <code>ele</code></li>
<li>add this regular expression pattern below the whole <code>birthInfo.css()</code> declaration:
<pre class="brush: jscript; title: ; notranslate">
var patt = /^[0-9]{2}\-[0-9]{2}\-[0-9]{4}$/i;
</pre>
</li>
<li>our previous <code>if()</code> statement has to become:
<pre class="brush: jscript; title: ; notranslate">
if(!patt.test(ele.val()))
</pre>
</li>
<li>validation message has to become <code>← type in date in correct format</code></li>
</ul>
<p>This is how <code>birthDate</code> method should look like after these changes:</p>
<pre class="brush: jscript; title: ; notranslate">
	'birthDate' : function (){

		$('body').append('&lt;div id=&quot;birthInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

		var birthInfo = $('#birthInfo');
		var ele = $('#birthday');
		var pos = ele.offset();

		birthInfo.css({
			top: pos.top-3,
			left: pos.left+ele.width()+15
		});

		var patt = /^[0-9]{2}\-[0-9]{2}\-[0-9]{4}$/i;

		if(!patt.test(ele.val())) {
			jVal.errors = true;
				birthInfo.removeClass('correct').addClass('error').html('&amp;larr; type in date in correct format').show();
				ele.removeClass('normal').addClass('wrong');
		} else {
				birthInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
				ele.removeClass('wrong').addClass('normal');
		}
	}
</pre>
<ul>
<li><em>Line 14:</em> It&#8217;s a regular expression pattern. It&#8217;s not our main focus in this tut, so let me just explain it very roughly. This pattern decides how the date format should look like, in this case it&#8217;s: <code>two digits</code> followed by <code>hyphen</code> then again <code>two digits</code> followed by <code>hyphen</code> and finally <code>four digits</code> at the end. So, the pattern applies for example to this date: <code>28-03-1987</code>.</li>
<li><em>Line 16:</em> We&#8217;re checking if date that user typed in conforms to our pattern from above.</li>
</ul>
<p>And of course, we need to bind this <code>birthDate</code> method to the &#8220;Date of birth&#8221; form field. It&#8217;s the same thing we did with <code>fullName</code> before, only with different names. Paste it at the bottom (outside of the <code>jVal</code> object), below our <code>fullName</code> binding declaration:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#birthday').change(jVal.birthDate);
</pre>
<p>And we have another fully working validation method. Great job!</p>
<h4 id="part5.6">Step 6: Validating User&#8217;s Gender</h4>
<p>Again, simply copy the whole <code>fullName</code> method, rename it to <code>gender</code> and apply these changes:</p>
<ul>
<li>all <code>nameInfo</code> occurences have to become <code>genderInfo</code></li>
<li>instead of <code>#fullname</code>, assign <code>#woman</code> element to variable <code>ele</code></li>
<li>in <code>genderInfo.css()</code> declaration, the <em>top</em> value has to become <code>top: pos.top-10</code> and the <em>left</em> value has to become <code>left: pos.left+ele.width()+60</code></li>
<li>our previous <code>if()</code> statement has to become:
<pre class="brush: jscript; title: ; notranslate">
if($('input[name=&quot;gender&quot;]:checked').length === 0)
</pre>
</li>
<li>validation message has to become <code>← are you a man or a woman?</code></li>
</ul>
<p>This is how <code>gender</code> method should look like after these changes:</p>
<pre class="brush: jscript; title: ; notranslate">
'gender' : function (){

	$('body').append('&lt;div id=&quot;genderInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

	var genderInfo = $('#genderInfo');
	var ele = $('#woman');
	var pos = ele.offset();

	genderInfo.css({
		top: pos.top-10,
		left: pos.left+ele.width()+60
	});

	if($('input[name=&quot;gender&quot;]:checked').length === 0) {
		jVal.errors = true;
			genderInfo.removeClass('correct').addClass('error').html('&amp;larr; are you a man or a woman?').show();
			ele.removeClass('normal').addClass('wrong');
	} else {
			genderInfo..removeClass('error').addClass('correct').html('&amp;radic;').show();
			ele.removeClass('wrong').addClass('normal');
	}
}
</pre>
<ul>
<li><em>Line 14:</em> We&#8217;re checking if user selected one of two radio buttons. <code>$('input[name="gender"]:checked')</code> selects all inputs with <code>name</code> &#8220;gender&#8221; (in this case all radio buttons) that are <strong>checked</strong>. Than we check if the number of selected radios (<code>.length</code>) equals <code>0</code>, which would mean that user didn&#8217;t select any.</li>
</ul>
<p>As always, we have to bind this <code>gender</code> method to our &#8220;Gender&#8221; radio buttons:</p>
<pre class="brush: jscript; title: ; notranslate">
$('input[name=&quot;gender&quot;]').change(jVal.gender);
</pre>
<p>There, another validation method completed. Three more to go :).</p>
<h4 id="part5.7">Step 7: Validating Vehicles Owned by User</h4>
<p>This time copy <code>gender</code> method, rename it to <code>vehicle</code> and apply following changes:</p>
<ul>
<li>all <code>genderInfo</code> occurences have to become <code>vehicleInfo</code></li>
<li>instead of <code>#woman</code>, assign <code>#ship</code> element to variable <code>ele</code></li>
<li>in <code>vehicleInfo.css()</code> declaration, the <em>left</em> value has to become <code>left: pos.left+ele.width()+40</code></li>
<li>our previous <code>if()</code> statement has to become:
<pre class="brush: jscript; title: ; notranslate">
if($('input[name=&quot;vehicle&quot;]:checked').length &lt;= 1)
</pre>
</li>
<li>validation message has to become <code>← I am sure you have at least two!</code></li>
</ul>
<p>This is how <code>vehicle</code> method should look like after these changes:</p>
<pre class="brush: jscript; title: ; notranslate">
'vehicle' : function (){

	$('body').append('&lt;div id=&quot;vehicleInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

	var vehicleInfo = $('#vehicleInfo');
	var ele = $('#ship');
	var pos = ele.offset();

	vehicleInfo.css({
		top: pos.top-10,
		left: pos.left+ele.width()+40
	});

	if($('input[name=&quot;vehicle&quot;]:checked').length &lt;= 1) {
		jVal.errors = true;
			vehicleInfo.removeClass('correct').addClass('error').html('&amp;larr; I am sure you have at least two!').show();
			ele.removeClass('normal').addClass('wrong');
	} else {
			vehicleInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
			ele.removeClass('wrong').addClass('normal');
	}
}
</pre>
<ul>
<li><em>Line 14:</em> Weíre checking if user selected two or more checkboxes. <code>$('input[name="vehicle"]:checked')</code> selects all inputs with name ìvehicleî (in this case all checkbox buttons) that are <strong>checked</strong>. Than we check if the number of selected checkboxes (<code>.length</code> method) equals or is less than <code>1</code>, which would mean that user didnít select any checkboxes or selected only one.</li>
</ul>
<p>Again, we have to bind this <code>vehicle</code> method to our &#8220;Vehicle&#8221; checkboxes:</p>
<pre class="brush: jscript; title: ; notranslate">
$('input[name=&quot;vehicle&quot;]').change(jVal.vehicle);
</pre>
<p>Tired? We have couple more methods to cover :). Time for email validation.</p>
<h4 id="part5.8">Step 8: Validating User&#8217;s Email Adress</h4>
<p>This time, copy our <code>birthDate</code> method, rename it to <code>email</code> and apply these changes:</p>
<ul>
<li>all <code>birthInfo</code> occurences have to become <code>emailInfo</code></li>
<li>instead of <code>#birthday</code>, assign <code>#email</code> element to variable <code>ele</code></li>
<li>our previous regular expression pattern has to become:
<pre class="brush: jscript; title: ; notranslate">
var patt = /^.+@.+[.].{2,}$/i;
</pre>
</li>
<li>validation message has to become <code>← give me a valid email adress, ok?</code></li>
</ul>
<p>This is how <code>email</code> method should look like after these changes:</p>
<pre class="brush: jscript; title: ; notranslate">
	'email' : function() {

		$('body').append('&lt;div id=&quot;emailInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

		var emailInfo = $('#emailInfo');
		var ele = $('#email');
		var pos = ele.offset();

		emailInfo.css({
			top: pos.top-3,
			left: pos.left+ele.width()+15
		});

		var patt = /^.+@.+[.].{2,}$/i;

		if(!patt.test(ele.val())) {
			jVal.errors = true;
				emailInfo.removeClass('correct').addClass('error').html('&amp;larr; give me a valid email adress, ok?').show();
				ele.removeClass('normal').addClass('wrong');
		} else {
				emailInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
				ele.removeClass('wrong').addClass('normal');
		}
	}
</pre>
<ul>
<li><em>Line 14:</em>For this tutorial I decided to go with very simple, almost basic regular expression pattern for email adress: <code>one or more characters</code> followed by <code> @ </code> smbol, then again <code>one or more characters</code> followed by <code> . </code> period, and at the end there should be <code>two or more characters</code>. So, the pattern applies to this email adress example: <code>mickey@mou.se</code></li>
</ul>
<p>Of course, bind this <code>.email</code> method to our &#8220;Email&#8221; form field:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#email').change(jVal.email);
</pre>
<p>Time for the last of our validation methods: <code>about</code>.</p>
<h4 id="part5.9">Step 9: Validating User&#8217;s About Info</h4>
<p>For this last method, copy <code>fullName</code>, rename it to <code>about</code> and apply following changes:</p>
<ul>
<li>all <code>nameInfo</code> occurences have to become <code>aboutInfo</code></li>
<li>instead of <code>#fullname</code>, assign <code>#about</code> element to variable <code>ele</code></li>
<li>our previous <code>if()</code> statement has to become:
<pre class="brush: jscript; title: ; notranslate">
if(ele.val().length &lt; 75)
</pre>
</li>
<li>validation message has to become <code>← come on, tell me a little bit more!</code></li>
</ul>
<p>This is how our <code>about</code> method should look like after these changes:</p>
<pre class="brush: jscript; title: ; notranslate">
	'about' : function() {

		$('body').append('&lt;div id=&quot;aboutInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

		var aboutInfo = $('#aboutInfo');
		var ele = $('#about');
		var pos = ele.offset();

		aboutInfo.css({
			top: pos.top-3,
			left: pos.left+ele.width()+15
		});

		if(ele.val().length &lt; 75) {
			jVal.errors = true;
				aboutInfo.removeClass('correct').addClass('error').html('&amp;larr; come on, tell me a little bit more!').show();
				ele.removeClass('normal').addClass('wrong').css({'font-weight': 'normal'});
		} else {
				aboutInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
				ele.removeClass('wrong').addClass('normal');
		}
	}
</pre>
<p>And of course we need to bind it to our &#8220;About&#8221; form field:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#about').change(jVal.about);
</pre>
<p>This is it! We just completed all our validation methods. It&#8217;s almost like they say: the end is nigh! There&#8217;s only two things left to do:</p>
<ul>
<li>build our last <code>sendIt</code> method</li>
<li>manage properly the <em>submit action</em> of the submit button</li>
</ul>
<h4 id="part5.10">Step 10: Final <code>sendIt</code> Method</h4>
<p>This method will be called after all our validation methods, as the last one, after clicking on the &#8220;submit&#8221; button. It will check if no errors occurred during validation (while performing any of our validation methods) up until the moment it&#8217;s called. The good news is, it couldn&#8217;t be more simple:</p>
<pre class="brush: jscript; title: ; notranslate">
'sendIt' : function (){
	if(!jVal.errors) {
		$('#jform').submit();
	}
</pre>
<ul>
<li><em>Line 2:</em> Remember that <code>errors</code> variable I told you we&#8217;re going to use later? Well, this &#8220;later&#8221; is right now :). If even one little error occurred during the validation, this <code>errors</code> variable was set to <code>true</code>. In human words it actually means something like: &#8220;yes, it&#8217;s <code>true</code> that we got some errors during validation&#8221;. So here we&#8217;re checking if it&#8217;s actually NOT <code>true</code>, which equals to no errors from validation.</li>
<li><em>Line 3:</em> If there were no errors, just finally <strong>submit</strong> the whole form.</li>
</ul>
<h4 id="part5.11">Step 11: Managing User&#8217;s Submit Action</h4>
<p>The only thing left now, is to manage what happens when the user clicks on our &#8220;submit&#8221; button. And it goes like this:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#send').click(function (){
	var obj = $.browser.webkit ? $('body') : $('html');
	obj.animate({ scrollTop: $('#jform').offset().top }, 750, function (){
		jVal.errors = false;
		jVal.fullName();
		jVal.birthDate();
		jVal.gender();
		jVal.vehicle();
		jVal.email();
		jVal.about();
		jVal.sendIt();
	});
	return false;
});
</pre>
<ul>
<li><em>Line 1:</em> We grab the <code>send</code> element, which is the &#8220;submit&#8221; button in our form, and if someone <code>click</code>s on it we perform all code below.</li>
<li><em>Line 2:</em> The thing is: when you want to apply scrolling to browser window, different browsers will work with different elements. And so: Chrome and Safari will work with <code>body</code>. Internet Explorer and Firefox will work with <code>html</code>. Opera will work with both. Unfortunately in our case we can&#8217;t just use <code>$('html, body')</code> to target both these elements (I&#8217;ll talk about that another time). So we need to somehow decide which of these elements we should apply scrolling to. And this is where jQuery comes with help. It provides us with <code>$.browser</code> property &#8211; it allows us to detect which browser we are working in. By using <code>$.browser.webkit</code> we&#8217;re just checking if our browser is running on webkit engine; if so then we assign <code>body</code> element to the <code>obj</code> variable we just created, if not we assign <code>html</code> element to it. <strong>Important note</strong>: <em>It should be avoided and it&#8217;s considered bad practice to perform any kind of &#8220;browser detection&#8221;, you should use &#8220;feature detection&#8221; instead</em>. But we can get away with that for our learning purposes.</li>
<li><em>Line 3:</em>We apply <code>scrollTop</code> animation to our <code>obj</code> element. The point that scrolling should stop is the beginning of the form, which is determined by accessing <em>top</em> value of its position in the document, which we get thanks to jQuery<code>offset()</code> function. Next we say that this scrolling animation should last <code>750</code> milliseconds, and when it&#8217;s done we&#8230;</li>
<li><em>Line 4:</em> Set variable <code>jVal.errors</code> to <code>false</code>, to clear errors that might occurred in previous validation, and then we&#8230;</li>
<li><em>Lines 5-11</em>: Call all our validation methods one by one, with <code>sendIt</code> method at the end, which will check if there were no errors and submit the whole form if so.</li>
<li><em>Line 13</em>:We return <code>false</code> to that <code>click</code> event of the &#8220;submit&#8221; button in our form, which means that the form won&#8217;t be submitted right away, the script will perform actions planned by us first.</li>
</ul>
<h2 id="part6">Final Product</h2>
<p>Right now our validation script is fully completed and should look like this:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){

	var jVal = {
		'fullName' : function() {

			$('body').append('&lt;div id=&quot;nameInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

			var nameInfo = $('#nameInfo');
			var ele = $('#fullname');
			var pos = ele.offset();

			nameInfo.css({
				top: pos.top-3,
				left: pos.left+ele.width()+15
			});

			if(ele.val().length &lt; 6) {
				jVal.errors = true;
					nameInfo.removeClass('correct').addClass('error').html('&amp;larr; at least 6 characters').show();
					ele.removeClass('normal').addClass('wrong');
			} else {
					nameInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
					ele.removeClass('wrong').addClass('normal');
			}
		},

		'birthDate' : function (){

			$('body').append('&lt;div id=&quot;birthInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

			var birthInfo = $('#birthInfo');
			var ele = $('#birthday');
			var pos = ele.offset();

			birthInfo.css({
				top: pos.top-3,
				left: pos.left+ele.width()+15
			});

			var patt = /^[0-9]{2}\-[0-9]{2}\-[0-9]{4}$/i;

			if(!patt.test(ele.val())) {
				jVal.errors = true;
					birthInfo.removeClass('correct').addClass('error').html('&amp;larr; type in date in correct format').show();
					ele.removeClass('normal').addClass('wrong');
			} else {
					birthInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
					ele.removeClass('wrong').addClass('normal');
			}
		},

		'gender' : function (){

			$('body').append('&lt;div id=&quot;genderInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

			var genderInfo = $('#genderInfo');
			var ele = $('#woman');
			var pos = ele.offset();

			genderInfo.css({
				top: pos.top-10,
				left: pos.left+ele.width()+60
			});

			if($('input[name=&quot;gender&quot;]:checked').length === 0) {
				jVal.errors = true;
					genderInfo.removeClass('correct').addClass('error').html('&amp;larr; are you a man or a woman?').show();
					ele.removeClass('normal').addClass('wrong');
			} else {
					genderInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
					ele.removeClass('wrong').addClass('normal');
			}
		},

		'vehicle' : function (){

			$('body').append('&lt;div id=&quot;vehicleInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

			var vehicleInfo = $('#vehicleInfo');
			var ele = $('#ship');
			var pos = ele.offset();

			vehicleInfo.css({
				top: pos.top-10,
				left: pos.left+ele.width()+40
			});

			if($('input[name=&quot;vehicle&quot;]:checked').length &lt;= 1) {
				jVal.errors = true;
					vehicleInfo.removeClass('correct').addClass('error').html('&amp;larr; I\'m sure you have at least two!').show();
					ele.removeClass('normal').addClass('wrong');
			} else {
					vehicleInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
					ele.removeClass('wrong').addClass('normal');
			}
		},

		'email' : function() {

			$('body').append('&lt;div id=&quot;emailInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

			var emailInfo = $('#emailInfo');
			var ele = $('#email');
			var pos = ele.offset();

			emailInfo.css({
				top: pos.top-3,
				left: pos.left+ele.width()+15
			});

			var patt = /^.+@.+[.].{2,}$/i;

			if(!patt.test(ele.val())) {
				jVal.errors = true;
					emailInfo.removeClass('correct').addClass('error').html('&amp;larr; give me a valid email adress, ok?').show();
					ele.removeClass('normal').addClass('wrong');
			} else {
					emailInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
					ele.removeClass('wrong').addClass('normal');
			}
		},

		'about' : function() {

			$('body').append('&lt;div id=&quot;aboutInfo&quot; class=&quot;info&quot;&gt;&lt;/div&gt;');

			var aboutInfo = $('#aboutInfo');
			var ele = $('#about');
			var pos = ele.offset();

			aboutInfo.css({
				top: pos.top-3,
				left: pos.left+ele.width()+15
			});

			if(ele.val().length &lt; 75) {
				jVal.errors = true;
					aboutInfo.removeClass('correct').addClass('error').html('&amp;larr; come on, tell me a little bit more!').show();
					ele.removeClass('normal').addClass('wrong').css({'font-weight': 'normal'});
			} else {
					aboutInfo.removeClass('error').addClass('correct').html('&amp;radic;').show();
					ele.removeClass('wrong').addClass('normal');
			}
		},

		'sendIt' : function (){
			if(!jVal.errors) {
				$('#jform').submit();
			}
		}
	};

// ====================================================== //

	$('#send').click(function (){
		var obj = $.browser.webkit ? $('body') : $('html');
		obj.animate({ scrollTop: $('#jform').offset().top }, 750, function (){
			jVal.errors = false;
			jVal.fullName();
			jVal.birthDate();
			jVal.gender();
			jVal.vehicle();
			jVal.email();
			jVal.about();
			jVal.sendIt();
		});
		return false;
	});

	$('#fullname').change(jVal.fullName);
	$('#birthday').change(jVal.birthDate);
	$('input[name=&quot;gender&quot;]').change(jVal.gender);
	$('input[name=&quot;vehicle&quot;]').change(jVal.vehicle);
	$('#email').change(jVal.email);
	$('#about').change(jVal.about);

});
</pre>
<div><a href="http://dl.dropbox.com/u/1715120/demos/real-time-form-validation-using-jquery/index.html"><img src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/live-demo-button.png" alt="Check out Live Demo for Real-Time jQuery Form Validation" width="570" height="50" /></a></div>
<h2 id="part7">After Word</h2>
<p>We&#8217;ve done it. Well, you have done it! I hope you enjoyed this tutorial and learned something. If you have <strong>any questions</strong> feel free to ask; I will be glad to talk more in the comments. Thanks for your time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/tutorials/building-real-time-form-validation-using-jquery/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
		</item>
		<item>
		<title>jQuery for Complete Beginners: Part 3</title>
		<link>http://www.1stwebdesigner.com/tutorials/jquery-for-complete-beginners-part-3/</link>
		<comments>http://www.1stwebdesigner.com/tutorials/jquery-for-complete-beginners-part-3/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 14:09:30 +0000</pubDate>
		<dc:creator>Jack Franklin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=11370</guid>
		<description><![CDATA[Welcome to the third post in this series, taking you from jQuery novice to jQuery expert. The past two weeks have essentially just listed functions that you will need to know. Today we are going to put the skills we&#8217;ve learned into practice (as well as meeting new things) and create a basic accordion. An [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/04/jquery3-thumb.png"><img class="alignleft size-full wp-image-11379" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/04/jquery3-thumb.png" alt="" width="150" height="150" /></a>Welcome to the third post in this series, taking you from jQuery novice to jQuery expert. The past two weeks have essentially just listed functions that you will need to know. Today we are going to put the skills we&#8217;ve learned into practice (as well as meeting new things) and create a basic accordion.</p>
<p>An accordion is a very good way of showing lots of content in a small area. You might have five headers, each with a paragraph below it. Showing all that at once is going to go down for a long way.<span id="more-11370"></span> With the accordion, only one paragraph is shown at a time, and users can click on the headers to view the content they wish. First we will build a simple one and then we will animate it. You&#8217;ll see just how many built-in functions jQuery includes that makes our lives much easier. You can see the online demo <a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/04/jquery3.html">here</a>.</p>
<p>Firstly I set up the accordion itself:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;h3&gt;Item 1
    &lt;p&gt;Item 1 content&lt;/p&gt;
    &lt;h3&gt;Item 2
    &lt;p&gt;Item 2 content&lt;/p&gt;
    &lt;h3&gt;Item 3
    &lt;p&gt;Item 3 content&lt;/p&gt;
    &lt;h3&gt;Item 4&lt;/h3&gt;
    &lt;p&gt;Item 4 content&lt;/p&gt;
</pre>
<p>And then just some very basic CSS to make it look a bit clearer:</p>
<pre class="brush: css; title: ; notranslate">
 p,h3 {margin: 0; padding: 0;}
        p {height: 150px; width: 200px; border: 1px solid black;}
        h3 {height: 50px; width: 200px; background-color: blue; color: white; border: 1px solid black;}
</pre>
<p>This leaves us with something similar to this. I&#8217;ve only taken a picture of the first two items to save space, and besides, the next two are identical.</p>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/04/jquery3-1.png"><img class="size-full wp-image-11374" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/04/jquery3-1.png" alt="" width="180" height="341" /></a></p>
<p>Now we can get onto the JavaScript. Include jQuery from the google CDN, add your script tags to the bottom of your page and away we go:</p>
<pre class="brush: jscript; title: ; notranslate">
var headings = $('h3'),
            paras = $('p');
</pre>
<p>All I am doing here is selecting all the heading 3 elements and all the paragraphs, and saving them to two arrays. Note the syntax, I could have done this:</p>
<pre class="brush: jscript; title: ; notranslate">
var headings = $('h3');
var paras = $('p');
</pre>
<p>However I find it quicker to just put a comma between them and emit one of the &#8216;var&#8217;s. It&#8217;s also more commonly done that way.</p>
<p>Once we&#8217;ve done that we now need to hide all but the first paragraph. This is done like so, using a function eq():</p>
<pre class="brush: jscript; title: ; notranslate">
paras.hide().eq(0).show();</pre>
<p>First I hide all the paragraphs and then use eq(0) to select the &#8217;0th&#8217; element of the &#8216;paras&#8217; array. In JavaScript (and most languages) arrays start from 0, so 0 will select the first element. Using eq(1) would select the second element. I then use jQuery&#8217;s show() function show the first one. This leave us with something like this:</p>
<p><a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/04/jquery3-1.png"><img class="size-full wp-image-11374" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/04/jquery3-1.png" alt="" width="180" height="341" /></a></p>
<p>And now we can write the code for hiding and showing. Firstly, we need to add a click event to our headers:</p>
<pre class="brush: jscript; title: ; notranslate">
 headings.click(function() {

 });
</pre>
<p>And we can write the code to go in it:</p>
<pre class="brush: jscript; title: ; notranslate">
 var cur = $(this); //save the element that has been clicked for easy referal
 cur.siblings('p').hide(); //hide all the paragraphs
 cur.next('p').show(); //get the next paragraph after the clicked header and show it
</pre>
<p>Lets go through this line by line:</p>
<pre class="brush: jscript; title: ; notranslate">
var cur = $(this);
</pre>
<p>Here we take the value of &#8216;this&#8217; and wrap it in the jQuery object before saving it to a variable &#8216;cur&#8217;. &#8216;this&#8217; refers to the current element being interacted with. In this case, it&#8217;s the heading element that has been clicked.</p>
<pre class="brush: jscript; title: ; notranslate">
cur.siblings('p').hide();
</pre>
<p>The jQuery siblings() function finds all elements on the same level as the current element. Here we find all the siblings of the current element that are paragraphs and hide them. So now we know that there are no paragraphs being shown.</p>
<pre class="brush: jscript; title: ; notranslate">
cur.next('p').show();
</pre>
<p>Finally we use jQuery&#8217;s next() function. This finds the next element from the one we have selected. In this case it finds the next paragraph and shows it.</p>
<p>And we&#8217;re done! If you try that in your browser, it works fine. However, seeing as jQuery gives us loads of animation functions, lets put a couple of those to use.</p>
<p>The two functions we will use are slideUp() and slideDown(). These do exactly what you would imagine, they animate an element sliding up until it&#8217;s gone, and then sliding it back down. In our click function that we wrote:</p>
<pre class="brush: jscript; title: ; notranslate">
 headings.click(function() {
            var cur = $(this); //save the element that has been clicked for easy referal
            cur.siblings('p').hide(); //hide all the paragraphs
            cur.next('p').show(); //get the next paragraph after the clicked header and show it
        })
</pre>
<p>Replace the hide() function with slideUp() and the show() function with slideDown():</p>
<pre class="brush: jscript; title: ; notranslate">
 headings.click(function() {
            var cur = $(this); //save the element that has been clicked for easy referal
            cur.siblings('p').slideUp(); //hide all the paragraphs
            cur.next('p').slideDown(); //get the next paragraph after the clicked header and show it
        })
</pre>
<p>And try now. Is it not beautiful?</p>
<p>That just about sums it up for this week. We&#8217;ve taken things discussed in the previous two weeks and put them together. We&#8217;ve also met another couple of functions to add to your jQuery repertoire.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/tutorials/jquery-for-complete-beginners-part-3/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>jQuery for Complete Beginners: Part 2</title>
		<link>http://www.1stwebdesigner.com/tutorials/jquery-complete-beginners-part-2/</link>
		<comments>http://www.1stwebdesigner.com/tutorials/jquery-complete-beginners-part-2/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 21:00:09 +0000</pubDate>
		<dc:creator>Jack Franklin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=7103</guid>
		<description><![CDATA[Welcome to part 2 of jQuery for beginners. In the first part we looked at how to add jQuery to our pages and also looked at how jQuery selects elements on the page before finally animating a div. In this lesson we are going to look purely at how to select elements through their relationship [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.1stwebdesigner.com/tutorials/jquery-complete-beginners-part-2"><img class="alignleft size-full wp-image-8028" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jquery2thumb.png" alt="" width="150" height="150" /></a>Welcome to part 2 of jQuery for beginners. In the first part we looked at how to add jQuery to our pages and also looked at how jQuery selects elements on the page before finally animating a div. In this lesson we are going to look purely at how to select elements through their relationship with the element we are already interacting with. This may seem complicated, but it&#8217;s in fact very straightforward.<span id="more-7103"></span></p>
<p>Essentially, if we have already selected an element, how can be traverse the page to find its parent element? We could just use another selector, but there are much better ways to do it. For example, take this HTML code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div&gt;
&lt;h2&gt;A header with &lt;a href=&quot;http://www.1stwebdesigner.com&quot;&gt;a link&lt;/a&gt; inside.
&lt;p&gt;A paragraph in the div&lt;/p&gt;
&lt;/div&gt;
</pre>
<p>And then using jQuery we had already selected the h2 element:</p>
<pre class="brush: jscript; title: ; notranslate">
$('h2').
</pre>
<p>How would we then select the div? We might just do a different selector:</p>
<pre class="brush: jscript; title: ; notranslate">$('div'). </pre>
<p>While this works fine in this case, imagine a much more complex site. Having rogue and vague selectors like that are not going to help. It would also mean giving other elements unnecessary &#8216;hooks&#8217;, such as an ID, just for the purpose of our JavaScript. In reality, jQuery makes it much easier:</p>
<pre class="brush: jscript; title: ; notranslate">
$('h2').parent(); //this would select the div.
</pre>
<p>This is the cusp of this lesson &#8211; to learn how we can be &#8216;sneaky&#8217; with our code to allow us to do less actual selecting and learn to work with what we already have.</p>
<p>Say now, instead of selecting the h2&#8242;s parent, we want to find its children, which in our case is the link. We could go back to CSS:</p>
<pre class="brush: jscript; title: ; notranslate">$('h2 a');</pre>
<p>But in reality, for reasons not worth divulging into at this moment, that takes a lot of work on jQuery&#8217;s part. What if, instead, jQuery provided a method to do the same thing? Well, it does!</p>
<pre class="brush: jscript; title: ; notranslate">('h2').children(); //selects the link element</pre>
<p>But what if the h2 element had more than one child element? jQuery actually allows us to pass in a selector to the children() function to be more specific:</p>
<pre class="brush: jscript; title: ; notranslate">
$('h2').children('a'); //selects all children of the h2 that are anchor elements.</pre>
<p>In our next example, let&#8217;s have a quick unordered list:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul&gt;
&lt;li&gt;Item 1&lt;/li&gt;
&lt;li&gt;Item 2&lt;/li&gt;
&lt;li&gt;Item 3&lt;/li&gt;
&lt;li&gt;Item 4&lt;/li&gt;
&lt;li&gt;Item 5&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Of course to select all the list items is as simple as:</p>
<pre class="brush: jscript; title: ; notranslate">$('li');</pre>
<p>Or you could use our new function:</p>
<pre class="brush: jscript; title: ; notranslate">$('ul').children();</pre>
<p>Generally which one you use depends on the situation on your page. For example, if I had two lists, one ordered (</p>
<ol>
<li>
<ul>) and only wanted to select the list items from one of those, I would use the latter of the two methods above.</ul>
</li>
<p>) and one unordered (</ol>
<p>If we want to interact with a specific item in that list, we can use another jQuery function, eq():</p>
<pre class="brush: jscript; title: ; notranslate">
$('li').eq(2); //selects list item 3</pre>
<p>Please note that it selects the 3rd item. This is because in most languages, the index is zero based. This means it starts from 0. So in our list, we have 5 items, the first of which you could call the &#8217;0th item&#8217;. If you struggle to remember this, just remember that you need to subtract one from the number you would usually use. Don&#8217;t worry, a few hours of coding and it will sink in.</p>
<p>Before we go any further it&#8217;s important for you to realise that one of the key principles of jQuery is its &#8216;chainability&#8217;. This means that functions can be run one after the other, or chained:</p>
<pre class="brush: jscript; title: ; notranslate">$('ul').children('li').eq(3).animate({...});</pre>
<p>The above code takes the following steps:<br />
1. $(&#8216;ul&#8217;) =&gt; Select all unordered lists on the page.<br />
2. children(&#8216;li&#8217;) =&gt; select all children of the lists that are list items.<br />
3. eq(3) =&gt; select the 2nd list item from each list.<br />
4 animate({&#8230;}) =&gt; animate that specific item. We covered basic animations in the last lesson.</p>
<p>Whilst the children() function only finds the immediate descendants of the selected item, jQuery provides a way to delve deeper. Going back to our HTML code we used much earlier:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div&gt;
&lt;h2&gt;A header with &lt;a href=&quot;http://www.1stwebdesigner.com&quot;&gt;a link&lt;/a&gt; inside.&lt;/h2&gt;
&lt;p&gt;A paragraph in the div&lt;/p&gt;
&lt;/div&gt;
</pre>
<p>If I had the following selector:</p>
<pre class="brush: jscript; title: ; notranslate">$('div');</pre>
<p>And now want to select the anchor element within the h2, you might think, correctly, to do this:</p>
<pre class="brush: jscript; title: ; notranslate">$('div').children('h2').children('a);</pre>
<p>Generally, as a rule of thumb, when you use the same function twice in a row, there is a better way to do it. And of course, there is, using jQuery&#8217;s find() method. Using this, the above line of code becomes:</p>
<pre class="brush: jscript; title: ; notranslate">$('div').find('a');</pre>
<p>The find function does not stop after the first descendants of the div element. It keeps going. It finds the immediate children, then the children of those children, and so on. Basically, find() searches all elements within the selected element, no matter how many levels down they are.</p>
<p>Next we have four basic functions to look at that allow us to select an element&#8217;s siblings. These are elements on the same level as the one currently selected. In our above HTML, the h2 &amp; p elements would be siblings. Take a look at the following functions:</p>
<pre class="brush: jscript; title: ; notranslate">
$('h2').next(); //selects the next sibling (the paragraph)
$('h2').nextAll(); //selects all the siblings after it.
$('p').prev(); //selects the previous sibling (the h2)
$('p').prevAll(); //selects the previous siblings
</pre>
<p>As you can see all of them are pretty simple, and handy if you need to jump along to the next element.</p>
<p>The final function we are going to look at is the siblings() function. Lets have a new block of HTML code to work with:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;p&gt;A paragraph&lt;/p&gt;
&lt;h2&gt;A heading&lt;/p&gt;
&lt;img src=&quot;somepic.jpg&quot; alt=&quot;A picture&quot;&gt;
&lt;h1&gt;A bigger heading&lt;/h1&gt;
</pre>
<p>From the first paragraph, we could use nextAll() to select all its siblings (as it&#8217;s the very first sibling):</p>
<pre class="brush: jscript; title: ; notranslate">
$('p').nextAll();</pre>
<p>But if we were at the h2 element, how could we select all its siblings? Easy:</p>
<pre class="brush: jscript; title: ; notranslate">$('h2').siblings();</pre>
<p>The siblings() function can also take a selector as an argument:</p>
<pre class="brush: jscript; title: ; notranslate">$('h2').siblings('p') //selects just the siblings that are paragraphs</pre>
<p>Just before I end, as a quick side note, last lesson, we spoke about including your jQuery at the very bottom of the page, before the final &lt;/body&gt; tag. However, you can include it in the header, or anywhere else in fact, if you add this line first:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {...});
</pre>
<p>What that does is makes sure the code you write runs after all the page content is loaded &#8211; otherwise you could be manipulating elements that have yet to load. ALl you do is wrap your jQuery in the above function:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
//all your jQuery code goes here like normal
});
</pre>
<p>That only applies if you add your code anywhere except before the closing &lt;/body&gt; tag.</p>
<p>The End</p>
<p>I hope you&#8217;ve enjoyed our brief foray into the world of jQuery selectors. In the next lesson we will get some cool stuff going and look at sliding elements in and out. We will also look at events and responding to, for example, an element being clicked. As always if you have any questions please feel free to leave a comment and I&#8217;ll answer them next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/tutorials/jquery-complete-beginners-part-2/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Presenting the Great New Features of jQuery UI 1.8</title>
		<link>http://www.1stwebdesigner.com/css/presenting-the-great-new-features-of-jquery-ui-1-8/</link>
		<comments>http://www.1stwebdesigner.com/css/presenting-the-great-new-features-of-jquery-ui-1-8/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 21:00:54 +0000</pubDate>
		<dc:creator>Daniel Kurdoghlian</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JS & AJAX]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=9305</guid>
		<description><![CDATA[The final version of jQuery UI 1.8 just got released a few days ago. I will go through all new features and also show you some examples with the new widgets. Along with the hundreds of bug fixes and improvements, 5 new plugins and 1 new effect found the way into the bundle. What’s New [...]]]></description>
			<content:encoded><![CDATA[<p>The final version of jQuery UI 1.8 just got released a few days ago. I will go through all new features and also show you some examples with the new widgets.</p>
<p>Along with the hundreds of bug fixes and improvements, 5 new plugins and 1 new effect found the way into the bundle.</p>
<p><span id="more-9305"></span></p>
<h2>What’s New in jQuery UI 1.8?</h2>
<p>The <a href="http://blog.jqueryui.com/2010/03/jquery-ui-18/" target="_blank">jQuery UI team</a> worked hard to make the framework even lighter, more modular and flexible. If you are a developer, it’s now even easier for you to build your own widgets or extend the pre-built ones.</p>
<p>To start right now, take a look at the new <a href="http://jqueryui.pbworks.com/" target="_blank">Widget-Factory</a> and the <a href="http://jqueryui.com/docs/Theming/API#The_jQuery_UI_CSS_Framework" target="_blank">jQuery UI CSS-Framework</a>.</p>
<p>Also don’t forget about the <a href="http://jqueryui.com/themeroller/developertool/">ThemeRoller Firefox Developer Bookmarklet</a>. This brings the ThemeRoller into any page on the web! To install it, simply drag the link into your Firefox toolbar. (or just click it right now to give it a try!).</p>
<h3>The Position Utility</h3>
<p>With this, you can position any element relative to any other, or even relative to the parent window or your mouse. Like in the “Write Less. Do More”-fashion, you just have to select the element you want and configuring which part of it should be positioned relative to which part of another element. That’s all!</p>
<p>Take a look at the <a href="http://jqueryui.com/demos/position/" target="_blank">official documentation here</a>.</p>
<p>You can also take a look at the two provided demos which are included.</p>
<h4>Position Utility &#8211; Demo 1:</h4>
<p><a href="http://jqueryui.com/demos/position/default.html" target="_blank">Link to the Demonstration</a></p>
<p><a href="http://jqueryui.com/demos/position/default.html"><img class="aligncenter size-full wp-image-9313" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jQueryUI-1.8-position-demo1.jpg" alt="jQuery UI 1.8 Position Demo 1" width="570" height="331" /></a></p>
<p>You can use the form controls to configure the positioning or you can drag the positioned elements to modify the offsets.</p>
<p>Just drag around the orange parent element to see the collision detection in action!</p>
<h4>Position Utility &#8211; Demo 2:</h4>
<p><a href="http://jqueryui.com/demos/position/cycler.html" target="_blank">Link to the Demonstration</a></p>
<p><a href="http://jqueryui.com/demos/position/cycler.html"><img class="aligncenter size-full wp-image-9314" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jQueryUI-1.8-position-demo2.jpg" alt="jQuery UI 1.8 Position Demo 2" width="570" height="294" /></a></p>
<p>This is a prototype of the photo-viewer using the Position Utility to place the images at the center, left and right of your parent and cycle them.</p>
<p>To cycle them, just click the “Previous” and “Next” links at the top or on the images on the left or right. Also take a look how the images are repositioned after you re-size the window.</p>
<h3>The Button Widget</h3>
<p>With the button widget you can create a fully theme-able button from any imaginable element you want to use as a native button.</p>
<p>Use them right now in your dialog boxes or forms.</p>
<p>Take a look at the <a href="http://jqueryui.com/demos/button/" target="_blank">official documentation here</a>.</p>
<p>They have also provided 6 different demonstrations there. Two of them I will show you now:</p>
<h4>Button Widget – Demo 1:</h4>
<p><a href="http://jqueryui.com/demos/button/default.html" target="_blank">Link to the Demonstration</a></p>
<p><a href="http://jqueryui.com/demos/button/default.html" target="_blank"></a><a href="http://jqueryui.com/demos/button/default.html"><img class="aligncenter size-full wp-image-9309" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jQueryUI-1.8-button-demo1.jpg" alt="jQuery UI 1.8 Button Demo 1" width="570" height="74" /></a><br />
You can use any markup for create your buttons: An ordinary button element, a form-input element with the submit type or an anchor tag.</p>
<pre class="brush: jscript; title: ; notranslate">
	$(&quot;button, input:submit, a&quot;, &quot;.demo&quot;).button();
	$(&quot;a&quot;, &quot;.demo&quot;).click(function() { return false; });
</pre>
<h4>Button Widget – Demo 2:</h4>
<p><a href="http://jqueryui.com/demos/button/toolbar.html" target="_blank">Link to the Demonstration</a></p>
<p><a href="http://jqueryui.com/demos/button/toolbar.html" target="_blank"></a><a href="http://jqueryui.com/demos/button/toolbar.html"><img class="aligncenter size-full wp-image-9310" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jQueryUI-1.8-button-demo2.jpg" alt="jQuery UI 1.8 Button Demo 2" width="570" height="74" /></a><br />
On this Demonstration you will see a (not functional) media player toolbar, filled with all types of buttons you can create with the new widget. Buttons with icons, checkbox-type buttons (<em>“Shuffle”</em>) and three radio-type buttons (<em>“No Repeat”, “Once” and “All”</em>).</p>
<p>Don’t forget to take a look at the source code. The setup/code is really very easy.</p>
<h3>The Autocomplete Widget</h3>
<p>This is maybe the most requested feature, which made it into the latest release of jQuery UI – The Autocomplete. Now you are able to make any text input field pop up a menu to help the user in completing their search or entry, provide suggestions or show all allowed values.</p>
<p>You are able to provide static data using the source option, or provide a callback function as the data source which can get the data from a server via Ajax.</p>
<p>Also there are a lot of demonstrations on the official documentation page. You can take a look at it here: <a href="http://jqueryui.com/demos/autocomplete/" target="_blank">Official Autocomplete Documentation</a>. I will again present you two of them:</p>
<h4>Autocomplete – Demo 1:</h4>
<p><a href="http://jqueryui.com/demos/autocomplete/default.html" target="_blank">Link to the Demonstration</a></p>
<p><a href="http://jqueryui.com/demos/autocomplete/default.html" target="_blank"></a><a href="http://jqueryui.com/demos/autocomplete/default.html"><img class="aligncenter size-full wp-image-9307" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jQueryUI-1.8-autocomplete-demo1.jpg" alt="jQuery UI 1.8 Autocomplete Demo 1" width="252" height="116" /></a></p>
<p>This is the demonstration with the default functionality. When you start typing, you will get static suggestions on the pop up box. The data source is a simple JavaScript array.</p>
<pre class="brush: jscript; title: ; notranslate">
	var availableTags = [&quot;c++&quot;, &quot;java&quot;, &quot;php&quot;, &quot;coldfusion&quot;, &quot;javascript&quot;, &quot;asp&quot;, &quot;ruby&quot;, &quot;python&quot;, &quot;c&quot;, &quot;scala&quot;, &quot;groovy&quot;, &quot;haskell&quot;, &quot;perl&quot;];
	$(&quot;#tags&quot;).autocomplete({
		source: availableTags
	});
</pre>
<h4>Autocomplete – Demo 2:</h4>
<p><a href="http://jqueryui.com/demos/autocomplete/remote-jsonp.html" target="_blank">Link to the Demonstration</a></p>
<p><a href="http://jqueryui.com/demos/autocomplete/remote-jsonp.html" target="_blank"></a><a href="http://jqueryui.com/demos/autocomplete/remote-jsonp.htmlI-1.8-autocomplete-demo2.jpg"><img class="aligncenter size-full wp-image-9308" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jQueryUI-1.8-autocomplete-demo2.jpg" alt="jQuery UI 1.8 Autocomplete Demo 2" width="471" height="302" /></a><br />
In this demonstration, the data source is a remote JSONP. In this case: <a href="http://geonames.org/" target="_blank">geonames.org webservice</a>. While you will end up with only the city name itself in the input box, more info is displayed in the suggestions box to help you find the correct entry.</p>
<p>This data is also available in callbacks, as you will get it illustrated in the results area below the text input field.</p>
<h3>Take A Look At The Complete Changelog</h3>
<p><a href="http://jqueryui.com/docs/Changelog/1.8" target="_blank">jQuery UI 1.8 – Final Changelog</a></p>
<p><a href="http://jqueryui.com/docs/Changelog/1.8I-1.8-changelog.jpg"><img class="aligncenter size-full wp-image-9311" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jQueryUI-1.8-changelog.jpg" alt="jQuery UI 1.8 Changelog" width="570" height="258" /></a></p>
<p>Click the link above to take a look at the full list of changes between jQuery UI 1.7.2 and jQuery UI 1.8.</p>
<h2>Downloading jQuery UI 1.8</h2>
<p><img class="alignleft size-full wp-image-9312" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/jQueryUI-1.8-download-it.jpg" alt="jQuery UI 1.8 Download It!" width="175" height="170" />Of course, you have a few options again to get the latest build of jQuery UI.</p>
<h3>The Complete Package:</h3>
<p>With the <a href="http://jqueryui.com/download/jquery-ui-1.8.custom.zip" target="_blank">jQuery UI 1.8 Starter Pack</a> you will get all components and the default themes. Also it is optimized to use it along the <a href="http://jqueryui.com/docs/Getting_Started" target="_blank">Getting Started Guide</a>, in case you’re new to this all.</p>
<h3>The Full Development Bundle:</h3>
<p>Of course you can also get the full <a href="http://jquery-ui.googlecode.com/files/jquery-ui-1.8.zip" target="_blank">jQuery UI 1.8 Development Bundle</a>, which also contains all components and the base theme. This package is optimized for development of jQuery UI itself or the redistribution of your own builds – not for the “Getting Started Guide”.</p>
<h3>The Full Theme Pack:</h3>
<p>With the <a href="http://jquery-ui.googlecode.com/files/jquery-ui-themes-1.8.zip" target="_blank">jQuery UI 1.8 Themes Pack</a> you will get all of the 21 Themes of the <a href="http://jqueryui.com/themeroller/" target="_blank">ThemeRoller Gallery</a>. You can just take one and use it, or take one as a starting point and tweak it to your wishes. For example you can use it along this <a href="http://jqueryui.com/themeroller/developertool/" target="_blank">bookmarklet</a>.</p>
<h3>Customized Download:</h3>
<p>If you know exactly what you want, you can go to the <a href="http://jqueryui.com/download" target="_blank">jQuery UI 1.8 Download Builder</a> to customize your build and download it as a custom zip file. Of course it still takes care of plugin dependencies, so you don’t have to worry about that!</p>
<h3>Other Download Sources:</h3>
<p>Now jQuery UI 1.8 is also hosted on <a href="http://code.google.com/apis/ajaxlibs/documentation/index.html#jqueryUI" target="_blank">Google’s AJAX Libraries API</a> page. As Usual you can directly use them in your script sources so you disburden your server.</p>
<ul>
<li>Minimized version: <a href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js" target="_blank">http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js</a></li>
<li>Full Version with comments: <a href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.js" target="_blank">http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.js</a></li>
<li>Always the latest 1.x build: <a title="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js">http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js</a></li>
</ul>
<p>Of course you can still go to <a href="http://github.com/jquery/jquery-ui" target="_blank">GitHub to get the latest version</a> there too.</p>
<h2>Last Words And Links</h2>
<p>If you are ready for jQuery UI 1.8, make sure to use it along the latest jQuery build (1.4+) so you get the full performance and compatibility.</p>
<p>The <strong>Core of jQuery UI is now 71% smaller</strong>. They have achieved this optimization by pulling the already modular but bundled components mouse and widget.</p>
<p>The new mouse plugin file makes the average <strong>jQuery UI 14% smaller</strong>. This plugin is not new, but now it is moved to its own file, where before it was in the core.</p>
<p>If you’re upgrading from 1.7 to 1.8, be sure to take a look at their comprehensive <a href="http://jqueryui.com/docs/Upgrade_Guide" target="_blank">Upgrade Guide here</a>. If you’re coming from an even older version, take a look at the <a href="http://jqueryui.com/docs/Upgrade_Guide_17" target="_blank">1.7 Upgrade Guide</a> first.</p>
<p><strong>Most interesting links:</strong></p>
<ul>
<li><a href="http://forum.jquery.com/developing-jquery-ui" target="_blank">jQuery UI Developer Forum</a></li>
<li><a href="http://jqueryui.com/docs/Changelog/1.8" target="_blank">Full Changelog</a></li>
<li><a href="http://dev.jqueryui.com/" target="_blank">jQuery UI Bug-Tracker</a></li>
<li><a href="http://jqueryui.pbworks.com/" target="_blank">jQuery UI Design &amp; Planning Wiki</a></li>
<li><a href="http://jqueryui.com/themeroller/developertool/">ThemeRoller Bookmarklet</a></li>
<li><a href="http://jqueryui.com/support" target="_blank">Support Center</a></li>
</ul>
<p>What can we expect from jQuery UI 1.9? I’m already very excited – Discuss in the comments and have fun trying out all new features and lets fill the web with some nice jQuery User Interfaces!</p>
<p>Happy developing! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/css/presenting-the-great-new-features-of-jquery-ui-1-8/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>How to Create a Flash-like Color and Pattern Morphing effect with jQuery</title>
		<link>http://www.1stwebdesigner.com/tutorials/create-flash-like-color-pattern-morphing-effect-jquery/</link>
		<comments>http://www.1stwebdesigner.com/tutorials/create-flash-like-color-pattern-morphing-effect-jquery/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 20:50:43 +0000</pubDate>
		<dc:creator>Daniel Kurdoghlian</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.1stwebdesigner.com/?p=8171</guid>
		<description><![CDATA[Today you will learn, how you can create a Flash-like effect with only using a few lines of jQuery and a transparent PNG as mask. Not only will you be able to dynamically change the color of the logo, but also add patterns as you wish and even animate them later with a few lines [...]]]></description>
			<content:encoded><![CDATA[<p>Today you will learn, how you can create a Flash-like effect with only using a few lines of jQuery and a transparent PNG as mask.</p>
<p>Not only will you be able to dynamically change the color of the logo, but also add patterns as you wish and even animate them later with a few lines of code. With this technique you will also be able to add transition effects and control any single part of the colors, patterns and animations.</p>
<p><span id="more-8171"></span></p>
<h2>Introduction and Demonstration</h2>
<p>You can take a look to the finished Demonstration <a href="http://pushingpixels.at/experiments/flash-like-color-morphing/">by  clicking here</a>. As you see, you will be able to adjust every single bit of  the color, transparency, pattern and even the animation itself.</p>
<p>If you want to follow along, you can <a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/Flash-like_Morphing.zip">download the finished project files here (zip archive)</a>.</p>
<p>This technique generally does not require any jQuery at all – but we are  using it, to make nice transitions and to be able to adjust the color, pattern  and animation by a few sliders.</p>
<h2>Step 1: Preparing the Mask and Pattern Images</h2>
<p><strong>The Key-PNG for this Effect:</strong></p>
<p>First you have to create a PNG-24 (24bit, so the alpha-channel gets saved  too) similar to this one:</p>
<p><img class="aligncenter size-full wp-image-8176" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/flash-like-masked-logo.jpg" alt="Masked-Logo" width="450" height="117" /></p>
<p>As you see, the transparency is not the outside of the logo. It is inside of  it, where you want to change the color, apply the gradients, add patterns and  animate them. The background should be exactly the same as in the container, in  which the logo is going to be. You can either use a single color or whatever  else you want to. Just take care if your background has a pattern so the  transition is seamless to your main background-pattern.</p>
<p><strong>The Pattern-PNG for the Animation Effect:</strong></p>
<p>The next image we will need is the one with the gradient and/or pattern. The  one I will use looks like this:</p>
<p><img class="aligncenter size-full wp-image-8177" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/flash-like-thepattern.jpg" alt="Pattern-howto" width="450" height="350" /></p>
<p>The dimensions of my pattern are 450 x 3000 pixel. The width should be  exactly the same as the PNG-mask. The height does not matter. The higher, the  better. Also make sure to remember the size. We will need it later in our script  to adjust the animation.</p>
<h2>Step 2: Arranging the Folders and the XHTML Structure</h2>
<p>Before we start creating our needed files, we first create our folder  structure again. It should look something like this again:</p>
<p><img class="aligncenter size-full wp-image-8178" src="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/folderstructure1.jpg" alt="Folder-Structure" width="163" height="86" /></p>
<p>Our index.html, which will be created at the root of this structure will need  <strong>following wrappers around the PNG-mask</strong>:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;wrapper&quot;&gt;
   &lt;div id=&quot;color&quot;&gt;&lt;/div&gt;
   &lt;div id=&quot;pattern&quot;&gt;&lt;/div&gt;
   &lt;div id=&quot;logobox&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>As you see here, we have 3 different wrappers for each element. The first one  will contain only the color. The second one only the pattern. And the last one  will only contain the PNG-mask, which also will be the topmost element.</p>
<p>Why three wrappers???</p>
<p>Maybe you ask yourself now, why we need 3 separate wrappers for each element,  if we can do the same with only one. This is why: With 3 separate wrappers, we  will be able to adjust different transparencies for every used element, without  worrying about loosing opacity on the pattern or the logo itself.</p>
<p>For the sliders we will use the latest jQuery UI again – so you don’t have to  worry too much about the structure there. Just make sure they have all the same  class and different ID’s.</p>
<p><strong>My Slider structure looks like this:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- color sliders --&gt;
&lt;div id=&quot;red&quot; class=&quot;slider&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;green&quot; class=&quot;slider&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;blue&quot; class=&quot;slider&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;alpha1&quot; class=&quot;slider&quot;&gt;&lt;/div&gt;

&lt;!-- pattern sliders --&gt;
&lt;div id=&quot;alpha2&quot; class=&quot;slider&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;speed&quot; class=&quot;slider&quot;&gt;&lt;/div&gt;
</pre>
<p>For the buttons I’m using ordinary a-tags – Just give them all the same class  and different ID’s again, so you can style them and bind different functions to  them. We will later escape the default link-behavior by returning “false” in the  script.</p>
<p><strong>Scripts and styles in the header:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;link rel=&quot;stylesheet&quot; href=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/black-tie/jquery-ui.css&quot; type=&quot;text/css&quot; media=&quot;all&quot; /&gt;

&lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot; type=&quot;text/css&quot; media=&quot;all&quot; /&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js&quot;&gt;&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-ui-1.8rc3.custom.min.js&quot;&gt;&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;js/script.js&quot;&gt;&lt;/script&gt;
</pre>
<p>For saving bandwidth, we will link to the Google files again. Unfortunately  the latest jQuery UI (version 1.8, release candidate 3) is not hosted there yet,  so you have to host in on your own server. You can <a href="http://jqueryui.com/download">customize the download yourself here</a>.  You will only need the UI Core and the Slider Widget.</p>
<p>I cannot use the latest stable release (version 1.7.2) because there is a  small “bug”, regarding the animation of the sliders, when changing the values  programmatically. You can take a look at the <a href="http://dev.jqueryui.com/ticket/4432">bug-tracker ticket here</a>. However,  it is resolved in the latest release candidate, so I will not go further into  the changes now.</p>
<p>Of course you can use the <a href="http://jqueryui.com/themeroller/">jQuery  UI ThemeRoller</a> to create your own slider-styles.</p>
<p>This time I will skip the CSS part completely because there is nothing  special to take care of. The only thing you maybe want to add is classes for  pattern-only settings and animation-only settings, so we can hide them later in  our script by only using the class names as selector.</p>
<h2>Step 3: Writing Some JavaScript Functions</h2>
<p>The first thing we have to do is to create document.ready function, so the  scripts start, as soon as the DOM is loaded and before the page contents are  loaded.</p>
<pre class="brush: jscript; title: ; notranslate">
$(function(){
   // put all your jQuery goodness in here.
});
</pre>
<p><strong>Now we will setup a few variables at first:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// color container
var color = $(&quot;#color&quot;);

// pattern  container
var pattern = $(&quot;#pattern&quot;);

//  animation start/stop button
var startstop = $(&quot;#startstop&quot;);

// show/hide button
var showhide = $(&quot;#showhide&quot;);

// random-color button
var randomcolors = $(&quot;#randomcolors&quot;);

// default animation speed (5ms to 100ms)
var speed = 50;

// starting position of  the pattern
var  curPos = 0;

//  reset-position
var resetPos = -(3000-117);
</pre>
<p>The last variable defines when our pattern hits the end, so we can start from  the beginning again – it will be for the animation later. 3000 is the height of  our pattern image and 117 is the height of our logo.</p>
<p>Don’t forget to put a minus in front of this value. The pattern will move up  in its container with the CSS background-position animated.</p>
<p><strong>Converting the slider-div’s to the jQuery UI sliders:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// setting up the jQuery UI sliders

$(&quot;#red, #green, #blue&quot;).slider({ animate:true, range:&quot;min&quot;, max:255, slide:colorChanger, change:colorChanger });

$(&quot;#red&quot;).slider(&quot;value&quot;, 52);
$(&quot;#green&quot;).slider(&quot;value&quot;, 174);
$(&quot;#blue&quot;).slider(&quot;value&quot;, 203);

$(&quot;#alpha1&quot;).slider({ animate:true,  range:&quot;min&quot;, max:100, value:100, slide:alphaChanger1, change:alphaChanger1 });

$(&quot;#alpha2&quot;).slider({ animate:true, range:&quot;min&quot;, max:100, value:100, slide:alphaChanger2, change:alphaChanger2 });

$(&quot;#speed&quot;).slider({ animate:true, range:&quot;min&quot;, min:5, max:100, value:50, slide:speedChange, change:speedChange });
</pre>
<p>This is everything you need, to “install” the sliders and setup the  starting-values and behaviors.</p>
<p>I will go true all options, so you know what you are doing here:</p>
<ul>
<li><strong>animate:</strong><strong>true</strong>: Smoothly scroll the handle  of the sliders to the position where the user clicked or to the value of our  random function. You can also also use one three predefined strings (“slow”,  “normal”, “fast”) or the number of milliseconds to run the animation (e.g. 500).</li>
<li><strong>range:”min”:</strong> This is optional – I’m using this, so I can  fill up the slider with a color or a pattern. With “min” the color/pattern will  go all the way from left to the position of the handle.</li>
<li><strong>min:5:</strong> The minimum value of the slider (used only on the  animation-speed slider).</li>
<li><strong>max:255:</strong> The maximum value of the slider.</li>
<li><strong>value:50:</strong> Setting the starting-value of the slider</li>
<li><strong>slide/change:</strong> Those two are events of the slider. They are  triggered when the user slides or changes the values. We are calling our  functions there which will be created in the next step.</li>
</ul>
<p>If you need more information about the options and events we are using, you  can take a look at the <a href="http://jqueryui.com/demos/slider/">documentation  here</a>.</p>
<p>Now everything is ready to create our main functions.</p>
<p><strong>Converting RGB to HEX</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// RGB to HEX converter (with 3 arguments)
function rgbToHex(r,g,b){

   var hex = [
      // converting strings to hex (16)
      r.toString(16),
      g.toString(16),
      b.toString(16)
   ];

   // get all 3 values of the array
   $.each(hex, function(nr, val){

      // make sure they are not empty
      if (val.length == 1){

         // add leading zero
         hex[nr] = &quot;0&quot; + val;
      }
   });

   // returns a valid hexadecimal  number
   return hex.join(&quot;&quot;).toUpperCase();
}
</pre>
<p>With this function, we will convert the values of the red, green and blue  sliders to a valid hexadecimal for using it in CSS.</p>
<p>For making this work, we need to pass 3 variables to the function (r,g,b) and  convert those strings to hex-code. We do so by using .toString(16).</p>
<p>We also wrapped them into an array, so we can go through them now by jQuery’s  each() loop, passing the index of the array (nr) and the value (val) to the  loop.</p>
<p>Last thing we need to to is to join those 3 values and converting them to  uppercase.</p>
<p><strong>Background-color Changer:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// changing the colors
function colorChanger(){

   // value of the &quot;red&quot;-slider
   var red = $(&quot;#red&quot;).slider(&quot;value&quot;);

   // value of the  &quot;green&quot;-slider
   var green = $(&quot;#green&quot;).slider(&quot;value&quot;);

   // value of the &quot;blue&quot;-slider
   var blue = $(&quot;#blue&quot;).slider(&quot;value&quot;);

   // converting values to hex
   var hex = rgbToHex(red,green,blue);

   // changing the background-color of  the wrapper
   color.css(&quot;background-color&quot;, &quot;#&quot; + hex);

}
</pre>
<p>This function will get all 3 values of our red-, green- and blue-sliders,  convert the values to a valid hex-code using the previous function and change  the css of our color-container.</p>
<p>That’s all! You should now be able to change the color of your logo. (You  have to comment out the alpha and the speed sliders, or you will get a  JavaScript error.)</p>
<p><strong>Opacity Changer:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// change the opacity of the color-wrapper
function alphaChanger1(){

   var opacity = $(&quot;#alpha1&quot;).slider(&quot;value&quot;) / 100;
   color.css(&quot;opacity&quot;, opacity );
}

// change the opacity of the pattern-wrapper
function alphaChanger2(){
   var opacity = $(&quot;#alpha2&quot;).slider(&quot;value&quot;) / 100;
   pattern.css(&quot;opacity&quot;, opacity );
}
</pre>
<p>Those two functions will handle the opacity of the color-wrapper and the  pattern-wrapper. Nothing special there. Just make sure to divide your value by  100, so you get a value between 0.00 and 1.00. This step is important because  the opacity attribute does not accept 3 digits as value. So a 50% opacity will  be 0.50.</p>
<p>You can also combine those two functions by passing the correct container  returning the right value. I skipped this step. It’s quick and dirty – but it  works! :)</p>
<p><strong>Function for the Animation:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// pattern animation
function patternScroller(){

   // substracting 1 with  every call
   curPos--;

   // if it hits  our reset-position, back to 0
   if (curPos == resetPos){ curPos = 0; }
   pattern.css(&quot;background-position&quot;, &quot;0 &quot; + curPos + &quot;px&quot;);
}
</pre>
<p>Every time this function gets called, we will subtract 1 from our current  position variable (curPos). If it hits the value of our reset position  (resetPos), we will set it back to 0. The last step there is to change the  vertical position of the background from our pattern-container.</p>
<p><strong>Speed Changer:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// animation speed changer
function speedChange(){

   // get the current value of the  speed-slider
   speed = $(&quot;#speed&quot;).slider(&quot;value&quot;);

   // clear interval,  if there is any
   clearInterval(initScroll);

   // set a new interval with the current speed
   initScroll = setInterval(patternScroller, speed);
}
</pre>
<p>This function will change the speed of our animation. First we need to get  the current value of our speed-slider. After this we have to clear any previous  interval (if there is any). Last but not least we are creating a new interval.  This will call our previous function (patternScroller) every x milliseconds. The  x stands for the value of our speed slider.</p>
<p><strong>Random Color and Alpha function:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// random color function
function randomColors(){
   $(&quot;#red&quot;).slider(&quot;value&quot;, Math.floor(Math.random()*256), true);
   $(&quot;#green&quot;).slider(&quot;value&quot;, Math.floor(Math.random()*256), true);
   $(&quot;#blue&quot;).slider(&quot;value&quot;, Math.floor(Math.random()*256), true);
   $(&quot;#alpha1&quot;).slider(&quot;value&quot;, Math.floor(Math.random()*101), true);
}
</pre>
<p>This function will change the values of the red, green, blue and alpha1  sliders randomly when called. It does so by using JavaScripts Math.random()  function. To make sure the returned value is not 0, just add 1 to the maximum  value. To make it a Integer we wrapped returned value into Math.floor(), so it  gets rounded downwards to the nearest integer.</p>
<p><strong>This function is now ready to be bound to button:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// random colors button
randomcolors.click(function(){

   // if button has  no &quot;random&quot; class
   if (!$(this).hasClass(&quot;random&quot;)){

      // add it
      $(this).addClass(&quot;random&quot;);

      // change the button text
      $(this).text(&quot;random-colors &amp; alpha: ON&quot;);

      // call the  random function once
      randomColors();

      // set a intervall with the random function
      randomizer = setInterval(randomColors, 2000);

   } else {

      // remove the class
      $(this).removeClass(&quot;random&quot;);

      // change the button text
      $(this).text(&quot;random-colors &amp; alpha: OFF&quot;);

      // clear the  interval
      clearInterval(randomizer);
   }

   // change the  default link-behavior
   return false;
});
</pre>
<p>We will check if the random-function is already running by adding and  removing a class (“random”) to the button.</p>
<p>The important parts of this whole function is setting/clearing the interval.  The interval will get called every 2 seconds (2000 milliseconds) and the first  call is after 2 seconds, so we are manually calling it the first time. By  returning false, we make sure the override the default behavior of a link.</p>
<p><strong>Show and Hide the Pattern container:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// show and hide the pattern
showhide.click(function(){

   // if button has no &quot;visible&quot;  class
   if (!pattern.hasClass(&quot;visible&quot;)){

      // add it
      pattern.addClass(&quot;visible&quot;);

      // change the text
      $(this).text(&quot;hide pattern&quot;);

      // fade in the pattern-container
      pattern.stop().fadeTo(1000, 1);

      // fade in all elements with the class &quot;forpattern&quot;
      $(&quot;.forpattern&quot;).stop().fadeTo(800,  1);

   } else {

      // remove the  class
      pattern.removeClass(&quot;visible&quot;);

      // change the button text
      $(this).text(&quot;show pattern&quot;);

      // fade out the pattern-container
      pattern.stop().fadeTo(800,  0);

      // fade out all elements with  the class &quot;forpattern&quot;
      $(&quot;.forpattern&quot;).stop().fadeTo(800, 0);
   }

   // change the default link-behavior
   return false;
});
</pre>
<p>Again we are checking if the pattern is hidden or not by adding and removing  a class to the button (“visible”). Nothing complicated in here – by now,  everything should be clear. Just to make sure: The second fade-effect is used to  show/hide all elements which have the class “forpattern”.</p>
<p><strong>Start and Stop the Animation:</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// start and stop the animation
startstop.click(function(){

   // if button has no  &quot;scrolling&quot; class
   if (!pattern.hasClass(&quot;scrolling&quot;)){

      // add it
      pattern.addClass(&quot;scrolling&quot;);

      // change the text
      $(this).text(&quot;stop animation&quot;);

      // start a new intervall with current speed-slider value
      initScroll = setInterval(patternScroller,  speed);

      // fade in  all elements with the &quot;foranimation&quot; class
      $(&quot;.foranimation&quot;).stop().fadeTo(800, 1);

   } else {

      // remove the class
      pattern.removeClass(&quot;scrolling&quot;);

      // change the button text
      $(this).text(&quot;start  animation&quot;);

      // clear the interval again
      clearInterval(initScroll);

      // fade out all elements with the &quot;foranimation&quot; class
      $(&quot;.foranimation&quot;).stop().fadeTo(800,  0);
   }

   // change the  default link-behavior
   return false;
});
</pre>
<p>This is the last button-function we need for this project.</p>
<p>It will start and stop the animation of our pattern. To distinguish if the  animation is already started or not, we are again adding and removing a class  (“scrolling”). If the button does not have this class yet we are adding it,  initiate an interval with the current value of our “speed” variable. If it has  this class, we remove it and clear this interval again. For a little bit eye  candy we are again fading all elements with the class “foranimation” in and  out.</p>
<h2>That’s All Folks!</h2>
<p>You should now have a Flash-like color and pattern morphing logo, using only  a transparent PNG as mask and a few jQuery functions. You can <a href="http://pushingpixels.at/experiments/flash-like-color-morphing/">take a look at the demo by clicking here</a> or <a href="http://cdn1.1stwebdesigner.com/wp-content/uploads/2010/03/Flash-like_Morphing.zip">download all files by clicking here</a>.</p>
<p>If you have any questions or need help with any of the steps, feel free to  ask them in the comments!</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.1stwebdesigner.com/tutorials/create-flash-like-color-pattern-morphing-effect-jquery/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
	</channel>
</rss>

