jquery

http://www.compoc.com/tuts/

Easy XML Consumption using jQuery

With the popularity of AJAX Web 2.0 style applications and the increase in web services it has become increasingly important to be able to parse XML from the client browser. This is not the easiest thing to do in a cross browser manner without the aid of a JavaScript library that supports XML. Fortunately jQuery makes XML utilization (almost) effortless. If you possess a basic understanding of how to program JavaScript then this tutorial will have you working with XML in 20 minutes.

To get started you will want to make some basic preparations:

  1. Make sure you use Firefox to run these examples. While you can certainly use IE, Firefox is less restrictive when it comes to running JavaScript from your local machine.
  2. Create a new directory for the sample files on your machine.
  3. Download the latest version of jQuery. Make sure to rename the file to jquery.js so it will work with these examples (by default the name will include the version and look something like jquery-1.2.3.min.js) and place the file into the root of the project directory you created.
  4. Download the following sample files and place the contents into the root of your project directory.
  5. Grab your favorite text editor or IDE and open those three files up. I recommend Notepad++ or Aptana.

The XML Data File

Below is a stripped down example of the XML file included. I assume you already know the basics of what XML is and how it is formed so I will only provide a quick breakdown of the most complex tag for those that need a light refresher. If you know basic XML you can skip this. Those unfamiliar with XML should check out SitePoints article titled "A Really Really Really Good Introduction to XML"

A. An xml tag. In this case the tag's title is "name"
B. A tag attribute named "post" which is assigned a value of "Class President"
C. The text inside the "name" tag with the value of "Gina Smith"

The HTML File

There is not much that is special about our html file. I kept it as clean as possible so you could concentrate on the JavaScript file that contains the jQuery code. Below are the only two portions of the html file that warrant some explanation.

The two lines of code illustrated above loads the jQuery library and our readXML JavaScript example.

I created a simple DIV that I called "ContentArea". Right now the DIV is blank. That will change when we dynamically update this object inside of the readXML JavaScript once the page has loaded.

The JavaScript readXML file

This is the file where most of the action is taking place. The jQuery library may make it easy to parse XML among many other things (that are also made equally simple) but the language tends to encourage the creation of compound functions which can make it a bit difficult to decipher for a newcomer. Not to worry, I have taken a few steps to make the information easier to digest:

  1. Color coded the examples to make following along more straight forward.
  2. Created short mini examples where each jQuery element is dissected.

The commands presented are the same as what you see in the readXML file but I have done my best to isolate them from any other code that does not help illustrate the jQuery concepts. Go ahead and minimize the readXML file if you have it open right now and concentrate on the mini-example below. When you open it back up in a few minutes you should have a better understanding of what the jQuery functions are doing.

The very colorful example below will wait until the DOM has loaded, read the students.xml file, cycle through each student record and store the name tag text into a variable. What we are not doing (yet) is anything useful with that data such as dynamically populating it into that empty DIV in the HTML file or storing the values in an array. Each time you see a change in color you are looking at a function within a function (and sometimes even those are within other functions).

 Note: Whenever you see a $, that is a shortcut for the function jQuery(). So $(document)… is the same as jQuery(document). This is good to know if you plan to use jQuery in tandem with another library such as prototype that uses the $ symbol as a shortcut.

The code segment below acts in a capacity similar to JavaScript's windows.onload statement. In this example we want to run our function once the DOM has been loaded.

A. $(document) – The document element refers to the DOM for the HTML page. The period tells us that the statement following should be applied to the selected element.
B. .ready – The ready command tells us that once the selected element "document" is ready to perform the actions within the parenthesis.
C. function() – This command creates and runs an unnamed function which includes everything encapsulated inside the brackets.

Note: Having no name for the function is ok if you just need to run it and won't need to reference it by name. If we wanted we could have given the function a name rather than leaving it blank.

Next we want to read the student.xml file and run a function that will be called "xml".

A. $.get – Runs the jQuery get function based on the parameters inside the parenthesis.
B. "students.xml" – The name of the file we are grabbing.
C. {} – Optional parameters left blank which we will not be taking advantage of in this tutorial.
D. function(xml) – Create a function named "xml" which encapsulates everything within the brackets that follow.

Note: We could have named this anything, I chose "xml" to be descriptive but in reality I could just as easily named it something else such as "studentRecords". Note: I chose to use the high level Ajax $.get function in jQuery. I could have just as easily used the $.post command or the lower level and more powerful (but not quite as simple to use) $.ajax command. Please see the Ajax section of the jQuery documentation for more information.

Each time we encounter the tag "student" in the file we will create and run an instance of a function which will be named "i".

A. $('student',xml) – Grab all 'student' tags from the xml object.
B. .each – Do whatever is within the ()'s one time for each instance of the statement to the left.
C. function(i) – Create a function named i running everything within the brackets

Note: In this statement I chose to assign the function with a name of "i" even though it is never referenced by name. You could delete the "i" leaving the function name blank and the code will still work as the current unnamed function can still be referenced by the "this" keyword.

Last we assign the text inside the "name" tag to the variable called "studentName".

A. studentName – The name of the variable we are assigning the value to.
B. $(this) – This function. (We are referring to the function we just created named 'i')
C. .find("name") – Find all instances of the "name" tag within the "student" tag. (We are making the assumption there will only be a single "name" tag within this instance of the "student" tag.)
D. .text() – Convert the value to text.

Now that you understand the snippet above let me introduce you to a few more jQuery commands that you might find useful before you take another look at the readXML code.

Grabbing XML tag attributes with jQuery

Capturing an XML attribute with jQuery is almost as simple as grabbing the text in between the tag. The code below is similar to the last line of code displayed. I'm only going to dissect the portion of the command that is different from the previous example where we were grabbing the tag text. Below we capture an XML tag attribute value.

A. .attr("post") – This grabs the attribute value titled "post".

Updating the content of a DIV dynamically

Once we know how to grab the data, we need to be able to display it. The following command will update a DIV tag populating it with the information contained in a string.

A. $("#ContentArea") – Selects the HTML element with an ID of "#ContentArea" (The DIV tag we created in the HTML example).
B. .append(myHTMLOutput) – adds the string assigned to the variable myHTMLOutput to the selected tag.

Another look at the JavaScript readXML file

Run the index.html file if you have not done so already. You should see the xml data organized in a table.

Open up that readXML file and take a second look. The jQuery commands should look more familiar to you. The extra code not featured in the tutorial is either straight JavaScript or jQuery commands that are very similar to what you have already seen.

When looking at the code the important thing for you to make note of is where the extra JavaScript code has been placed. I chose to build my HTML (which I eventually populate into the empty DIV) in one string variable. It was important that I created the string variable and populated it with the beginning table code including the header row before the $('student,xml).each statement. This ensures that the information is updated only once before the reading of the XML record begins.

You will also notice that I have created a function to help build the HTML string variable that I named BuildStudentHTML. This is just regular run of the mill JavaScript code. The only code in that function you may want to take note of is the if statement. I evaluate the variable "studentPost". If the "name" tag does not have the "post" attribute then it will be undefined. This provides me a means of discriminating between instances of the "name" tags that do and do not possess this attribute when evaluated.

Another thing I do is place my HTML table closing tag into the string variable after the closing of the $('student,xml).each statement, since we only want to add the end table tag information to the string once. Last we update our DIV populating it with the HTML string we built in our jQuery code.

Summary

You should now be able to adapt what you have learned to parse XML files with ease utilizing jQuery. This tutorial only scratches the surface of what this dynamic JavaScript library is capable of. For more information check out the reference links provided below.

Reference

SitePoint Articles:

Other References:

--
Thanks
Suresh Devaraj

Compressing your JavaScript with Closure Compiler


Compressing your JavaScript with Closure Compiler

Author: Robert Bowdidge, Software Engineer
Recommended experience: Some experience creating web pages.

Overview

The best way to make your web page more responsive is to minimize the number of files and size of files that must be downloaded when the page is loaded. Reducing the number of files loaded avoids hitting maximum simultaneous download limits in browsers. Reducing file size cuts the time needed to send all the bytes over the Internet. Some tools already exist to minimize files and file sizes. Spriting tools and image compression tools let you minimize the number and size of images; gzip and HTML compression tools let you reduce the size of your HTML files.
JavaScript minimization tools give you another way to reduce your overall download size. These tools work on JavaScript source code for your webpage. The tools remove unneeded spaces and comments, and sometimes even change the names of variables in your program to shrink the file size even more. However, the commonly used minimization tools miss additional ways to compress the code even further.

The Closure Compiler, a new minimization tool, finds ways to compress your JavaScript code even further than existing minimization tools. It achieves additional compression by using compiler-like technology to rewrite your JavaScript into a much smaller form, while ensuring the code still runs correctly. Closure Compiler can condense several files into one single file, and can easily reduce the size of your JavaScript in half. The Closure Compiler also does syntactic checks and static analysis for your program, so it flags potential syntax and type errors and highlights code patterns that may not work well on all browsers.

How can I use the Closure Compiler?

You can use the Closure Compiler as:

An open source Java application that you can run from the command line.

A simple web application.

A RESTful API.

To get started with the compiler, see "How do I start" to the right.

What are the benefits of using Closure Compiler?

  • Efficiency. The Closure Compiler reduces the size of your JavaScript files and makes them more efficient, helping your application to load faster and reducing your bandwidth needs.
  • Code checking. The Closure Compiler provides warnings for illegal JavaScript and warnings for potentially dangerous operations, helping you to produce JavaScript that is less buggy and and easier to maintain.

Example: What Can Closure Compiler Do For You?

The Hello World of the Closure Compiler Service UI

The easiest way to get familiar with the Closure Compiler service is by optimizing a few simple functions in the service's web UI.
  1. Access the Closure Compiler UI by opening this page in another tab or window: http://closure-compiler.appspot.com.
  2. You should see the Closure Compiler UI prepopulated with a simple Hello World function:

  3. Click "Compile" to see the result:


That's it! You now have a much smaller version of the JavaScript code that functions identically to the original. The Closure Compiler service reduced the code from 92 bytes to just 55 bytes by removing comments and whitespace and renaming basic symbols.
For your convenience, the Closure Compiler service hosts the output file default.js on its servers for one hour. You can access the URL of the output file by copying the location of the link that's provided above the output pane, where it says The code may also be accessed at {filename}. If you make any changes to the original JavaScript code and re-optimize it during that hour, Closure Compiler service overwrites the output file with the new results as long as you leave the @output_file_name parameter unchanged at the top of the input field. You can use this feature as a quick way to test your compiled code by linking directly to the file from your test application. Do do not link to it from production servers.
Note: To prevent abuse, the Closure Compiler limits the number of consecutive compiles that you can run. If you see the message Too many compiles performed recently. Try again later, it means you've temporarily exceeded the limit.

Optimize a JavaScript file

You can also optimize the contents of one or more JavaScript files using the Closure Compiler UI.
  1. Copy and paste the URL http://code.google.com/closure/compiler/samples/tutorial2.js into the Add a URL box. This file contains unoptimized code for creating nodes in a DOM tree.
  2. Click Add. (If you had more than one file to add, repeat Steps 1 and 2 until you've added all of them. You can also type the file name(s) directly into the text area if you prefer.)
  3. If you want the Closure Compiler service to serve the compressed file, choose a name for the output file using the @output_file_name parameter at the top of the input field. Note that the default for the output file name is default.js but you should change it to a more meaningful name for your project. Also note that the Closure Compiler service hosts the output file on its servers for an hour.
  4. Click Compile.

You should see the optimized JavaScript in the right hand panel, like this:
To use the optimized code, you can cut and paste it into your source file, download the file into your directory, or link to the file directly in your script tag (for up to one hour).
You have just worked through examples of optimizing simple functions in the Closure Compiler service UI. If you'd like to build the Closure Compiler service's JavaScript optimization process into a larger system, then you should talk directly to the Closure Compiler service API. Learn more at Getting Started with the Closure Compiler Service API.

--
Thanks
Suresh Devaraj

Using HTML 5 for performance improvements

Using HTML 5 for performance improvements

Author: Jens Meiert, Google Webmaster

Recommended experience: Basic/Advanced HTML

In HTML, you can already reduce content size significantly by omitting optional tags. HTML 5, which is still under development, offers you a couple more options to decrease your file size beside leaving out optional stuff. Here we'll feature some basic measures to reduce content size a bit more, plus the async and defer attributes useful to improve script execution.

DTD

HTML 5 allows you to set the document type by just stating (in any form, as the DTD is case-insensitive)

<!DOCTYPE html>

Compare that to

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

and you'll notice that the HTML 5 DTD is much shorter.

Encoding

When you specify the encoding of your document, HTML 5 is a bit easier to use and also more lightweight:

<meta charset="utf-8">

will do what

<meta http-equiv="content-type" content="text/html; charset=utf-8">

does otherwise; your browser usually knows that it's dealing with HTML.

type attributes

Another thing that works in HTML 5 – today – is that you can leave out all the type attributes related to MIME types. These are the attributes such as type="text/css" or type="text/javascript", which describe the type of contents the element in question contains or links to.

Instead of <style type="text/css"> you can just write <style>; instead of writing <script type="text/javascript">, you can just use <script>. You can omit type="text/css" in almost all document types actually, even in XHTML, but HTML 5 makes all this even simpler since consistent.

async (and defer)

async and defer are attributes to be used in conjunction with the script element.

To explain why these attributes are useful to improve performance, it's best to see what happens when they're not used – respective script would be fetched and executed immediately, before the user agent (browser) continues parsing the page. Sometimes this behavior is desirable, sometimes it's not.

The new async attribute allows that respective script will be executed asynchronously, as soon as it is available. HTML 4, which already includes the defer attribute, states that defer "provides a hint to the user agent that the script is not going to generate any document content (e.g., no document.write in JavaScript) and thus, the user agent can continue parsing and rendering".

If the async attribute is not used but the defer attribute is present, the script is executed when the page has finished parsing. The defer attribute may be specified even if the async attribute is specified. This allows legacy browsers that only know defer to fall back to the defer behavior instead of the synchronous blocking behavior that is the default.


--
Thanks
Suresh Devaraj

The 30 CSS Selectors you Must Memorize

http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/


1. *

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }

Let’s knock the obvious ones out, for the beginners, before we move onto the more advanced selectors.

The star symbol will target every single element on the page. Many developers will use this trick to zero out the margins and padding. While this is certainly fine for quick tests, I’d advise you to never use this in production code. It adds too much weight on the browser, and is unnecessary.

The * can also be used with child selectors.

  1. #container * {
  2. border: 1px solid black;
  3. }

This will target every single element that is a child of the #container div. Again, try not to use this technique very much, if ever.

View Demo

Compatibility

  • IE6+
  • Firefox
  • Chrome
  • Safari
  • Opera

2. #X

  1. #container {
  2. width: 960px;
  3. margin: auto;
  4. }

Prefixing the hash symbol to a selector allows us to target by id. This is easily the most common usage, however be cautious when using id selectors.

Ask yourself: do I absolutely need to apply an id to this element in order to target it?

id selectors are rigid and don’t allow for reuse. If possible, first try to use a tag name, one of the new HTML5 elements, or even a pseudo-class.

View Demo

Compatibility

  • IE6+
  • Firefox
  • Chrome
  • Safari
  • Opera

3. .X

  1. .error {
  2. color: red;
  3. }

This is a class selector. The difference between ids and classes is that, with the latter, you can target multiple elements. Use classes when you want your styling to apply to a group of elements. Alternatively, use ids to find a needle-in-a-haystack, and style only that specific element.

View Demo

Compatibility

  • IE6+
  • Firefox
  • Chrome
  • Safari
  • Opera

4. X Y

  1. li a {
  2. text-decoration: none;
  3. }

The next most comment selector is the descendant selector. When you need to be more specific with your selectors, you use these. For example, what if, rather than targeting all anchor tags, you only need to target the anchors which are within an unordered list? This is specifically when you’d use a descendant selector.

Pro-tip – If your selector looks like X Y Z A B.error, you’re doing it wrong. Always ask yourself if it’s absolutely necessary to apply all of that weight.

View Demo

Compatibility

  • IE6+
  • Firefox
  • Chrome
  • Safari
  • Opera

5. X

  1. a { color: red; }
  2. ul { margin-left: 0; }

What if you want to target all elements on a page, according to their type, rather than an id orclassname? Keep it simple, and use a type selector. If you need to target all unordered lists, use ul {}.

View Demo

Compatibility

  • IE6+
  • Firefox
  • Chrome
  • Safari
  • Opera

6. X:visited and X:link

  1. a:link { color: red; }
  2. a:visted { color: purple; }

We use the :link pseudo-class to target all anchors tags which have yet to be clicked on.

Alternatively, we also have the :visited pseudo class, which, as you’d expected, allows us to apply specific styling to only the anchor tags on the page which have been clicked on, or visited.

View Demo

Compatibility

  • IE7+
  • Firefox
  • Chrome
  • Safari
  • Opera

7. X + Y

  1. ul + p {
  2. color: red;
  3. }

This is referred to as an adjacent selector. It will select only the element that is immediately preceded by the former element. In this case, only the first paragraph after each ul will have red text.

View Demo

Compatibility

  • IE7+
  • Firefox
  • Chrome
  • Safari
  • Opera

8. X > Y

  1. div#container > ul {
  2. border: 1px solid black;
  3. }

The difference between the standard X Y and X > Y is that the latter will only select direct children. For example, consider the following markup.

  1. <div id="container">
  2. <ul>
  3. <li> List Item
  4. <ul>
  5. <li> Child li>
  6. ul>
  7. li>
  8. <li> List Item li>
  9. <li> List Item li>
  10. <li> List Item li>
  11. ul>
  12. div>

A selector of #container > ul will only target the uls which are direct children of the div with an id ofcontainer. It will not target, for instance, the ul that is a child of the first li.

For this reason, there are performance benefits in using the child combinator. In fact, it’s recommended particularly when working with JavaScript-based CSS selector engines.

View Demo

Compatibility

  • IE7+
  • Firefox
  • Chrome
  • Safari
  • Opera

9. X ~ Y

  1. ul ~ p {
  2. color: red;
  3. }

This sibling combinator is similar to X + Y, however, it’s less strict. While an adjacent selector (ul + p) will only select the first element that is immediately preceded by the former selector, this one is more generalized. It will select, referring to our example above, any p elements, as long as they follow a ul.

View Demo

Compatibility

  • IE7+
  • Firefox
  • Chrome
  • Safari
  • Opera

10. X[title]

  1. a[title] {
  2. color: green;
  3. }

Referred to as an attributes selector, in our example above, this will only select the anchor tags that have atitle attribute. Anchor tags which do not will not receive this particular styling. But, what if you need to be more specific? Well…

View Demo

Compatibility

  • IE7+
  • Firefox
  • Chrome
  • Safari
  • Opera

11. X[href="foo"]

  1. a[href="http://net.tutsplus.com"] {
  2. color: #1f6053; /* nettuts green */
  3. }

The snippet above will style all anchor tags which link to http://net.tutsplus.com; they’ll receive our branded green color. All other anchor tags will remain unaffected.

Note that we’re wrapping the value in quotes. Remember to also do this when using a JavaScript CSS selector engine. When possible, always use CSS3 selectors over unofficial methods.

This works well, though, it’s a bit rigid. What if the link does indeed direct to Nettuts+, but, maybe, the path isnettuts.com rather than the full url? In those cases we can use a bit of the regular expressions syntax.

View Demo

Compatibility

  • IE7+
  • Firefox
  • Chrome
  • Safari
  • Opera

12. X[href*="nettuts"]

  1. a[href*="tuts"] {
  2. color: #1f6053; /* nettuts green */
  3. }

There we go; that’s what we need. The star designates that the proceeding value must appear somewherein the attribute’s value. That way, this covers nettuts.com, net.tutsplus.com, and even tutsplus.com.

Keep in mind that this is a broad statement. What if the anchor tag linked to some non-Envato site with the string tuts in the url? When you need to be more specific, use ^ and &, to reference the beginning and end of a string, respectively.

View Demo

Compatibility

  • IE7+
  • Firefox
  • Chrome
  • Safari
  • Opera

13. X[href^="http"]

  1. a[href^="http"] {
  2. background: url(path/to/external/icon.png) no-repeat;
  3. padding-left: 10px;
  4. }

Ever wonder how some websites are able to display a little icon next to the links which are external? I’m sure you’ve seen these before; they’re nice reminders that the link will direct you to an entirely different website.

This is a cinch with the carat symbol. It’s most commonly used in regular expressions to designate the beginning of a string. If we want to target all anchor tags that have a href which begins with http, we could use a selector similar to the snippet shown above.

Notice that we’re not searching for http://; that’s unnecessary, and doesn’t account for the urls that begin with https://.

Now, what if we wanted to instead style all anchors which link to, say, a photo? In those cases, let’s search for the end of the string.

View Demo

Compatibility

  • IE7+
  • Firefox
  • Chrome
  • Safari
  • Opera

14. X[href$=".jpg"]

  1. a[href$=".jpg"] {
  2. color: red;
  3. }

Again, we use a regular expressions symbol, $, to refer to the end of a string. In this case, we’re searching for all anchors which link to an image — or at least a url that ends with .jpg. Keep in mind that this certainly won’t work for gifs and pngs.

View Demo

Compatibility

  • IE7+
  • Firefox

There we go; that fixes it!

View Demo

Compatibility

  • IE9+
  • Firefox
  • Chrome
  • Safari
  • Opera

Yep - IE8 supported :first-child, but not :last-child. Go figure.


28. X:only-child

  1. div p:only-child {
  2. color: red;
  3. }

Truthfully, you probably won't find yourself using the only-child pseudo class too often. Nonetheless, it's available, should you need it.

It allows you to target elements which are the only child of its parent. For example, referencing the snippet above, only the paragraph that is the only child of the div will be colored, red.

Let's assume the following markup.

  1. <div><p> My paragraph here. p>div>
  2. <div>
  3. <p> Two paragraphs total. p>
  4. <p> Two paragraphs total. p>
  5. div>

In this case, the second div's paragraphs will not be targeted; only the first div. As soon as you apply more than one child to an element, the only-child pseudo class ceases to take effect.

View Demo

Compatibility

  • IE9+
  • Firefox
  • Chrome
  • Safari
  • Opera

29. X:only-of-type

  1. li:only-of-type {
  2. font-weight: bold;
  3. }

This structural pseudo class can be used in some clever ways. It will target elements that do not have any siblings within its parent container. As an example, let's target all uls, which have only a single list item.

First, ask yourself how you would accomplish this task? You could do ul li, but, this would target all list items. The only solution is to use only-of-type.

  1. ul > li:only-of-type {
  2. font-weight: bold;
  3. }
View Demo

Compatibility

  • IE9+
  • Firefox 3.5+
  • Chrome
  • Safari
  • Opera

30. X:first-of-type

The first-of-type pseudo class allows you to select the first siblings of its type.

A Test

To better understand this, let's have a test. Copy the following mark-up into your code editor:

  1. <div>
  2. <p> My paragraph here. p>
  3. <ul>
  4. <li> List Item 1 li>
  5. <li> List Item 2 li>
  6. ul>
  7. <ul>
  8. <li> List Item 3 li>
  9. <li> List Item 4 li>
  10. ul>
  11. div>

Now, without reading further, try to figure out how to target only "List Item 2". When you've figured it out (or given up), read on.

Solution 1

There are a variety of ways to solve this test. We'll review a handful of them. Let's begin by using first-of-type.

  1. ul:first-of-type > li:nth-child(2) {
  2. font-weight: bold;
  3. }

This snippet essentially says, "find the first unordered list on the page, then find only the immediate children, which are list items. Next, filter that down to only the second list item in that set.

Solution 2

Another option is to use the adjacent selector.

  1. p + ul li:last-child {
  2. font-weight: bold;
  3. }

In this scenario, we find the ul that immediately proceeds the p tag, and then find the very last child of the element.

Solution 3

We can be as obnoxious or as playful as we want with these selectors.

  1. ul:first-of-type li:nth-last-child(1) {
  2. font-weight: bold;
  3. }

This time, we grab the first ul on the page, and then find the very first list item, but starting from the bottom!:)

View Demo

Compatibility

  • IE9+
  • Firefox 3.5+
  • Chrome
  • Safari
  • Opera

Conclusion

If you're compensating for older browsers, like Internet Explorer 6, you still need to be careful when using these newer selectors. But, please don't let that deter you from learning these. You'd be doing a huge disservice to yourself. Be sure to refer here for a browser-compatibility list. Alternatively, you can use Dean Edward's excellent IE9.js script to bring support for these selectors to older browsers.

Secondly, when working with JavaScript libraries, like the popular jQuery, always try to use these native CSS3 selectors over the library's custom methods/selectors, when possible. It'll make your code faster, as the selector engine can use the browser's native parsing, rather than its own.

Thanks for reading, and I hope you picked up a trick or two!