Telerik blogs

This article is taken from How jQuery Works.


jQuery uses an interesting concept called a "Builder" to make its code short and simple. The Builder pattern is an object-oriented programming design pattern that has been gaining popularity.

In a nutshell: Every method within jQuery returns the query object itself, allowing you to 'chain' upon it, for example:

       alert("You are now leaving the site.");
       return false;

Which would work against the following HTML:

<a href="" class="clickme">I give a message when you leave</a>
 <a href="" class="hideme">Click me to hide!</a>
 <a href="">I'm a normal link</a>

Methods that modify the jQuery selection and can be undone with end(), are the following:

  • add(),
  • children(),
  • eq(),
  • filter(),
  • find(),
  • gt(),
  • lt(),
  • next(),
  • not(),
  • parent(),
  • parents() and
  • siblings().

Please check the Traversing API documentation for details of these methods.

About the Author

Iana Tsolova

is Product Manager at Telerik’s DevTools division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.


Comments are disabled in preview mode.