jQuery: Difference between .each and jQuery.each

It can be quite confusing when you have 2 methods in an API with same names. Hopefully, this post will clear up your doubts.

.each is an iterator that is used to iterate over only jQuery objects collection while jQuery.each is a general function for iterating over javascript objects and arrays.

Still confused? Let us look at the usage of both of these with examples.


Consider the following markup.

<p> paragraph element </p> span element

Suppose we want to find out the tag name of each element present inside this div. In this case we will use .each iterator
Continue reading

Guys, I am writing a book

PHP jQuery Cookbook

Yes that’s right and it is called PHP jQuery Cookbook.  As the name suggests, it’s about creating rich internet applications using 2 of my favorite technologies – PHP and jQuery.

I love coding web apps and helping others find solutions. Perhaps that is the reason I agreed to write when the wonderful people at Packt Publishing contacted me. (Also, a book on resume isn’t that bad either ;))

Another reason is I love Open source. It is a lovely philosophy and I am a strong believer in it. Having learnt so much from the Open source community since I started coding, I have always wanted to return something back. Nothing could have been better then this. And did I mention, Packt pays direct royalty to a project if they sell a book written on the same.

Continue reading

jQuery Tip: Finding tag name of an element

While coding jQuery or javascript, sometimes we need the tag name of an element. This post will show how you can retrieve the tag name of an element easily using jQuery

We know that each DOM element has a tagName property. We also know that most jQuery methods return jQuery object. Therefore to get the tagName, we need to extract the DOM element from it. This can be achieved in 2 ways.

Method 1: Using get() method of jQuery

jQuery’s get() method returns the collection of DOM elements for a jQuery collection.

Consider the following markup

This is a div

Continue reading

Goggle’s new book on browsers and web – 20 things I learned

20 Things I Learned

Google has created a new interactive book called “20 things I learned about browsers and the web“. It has 20 small chapters each answering a topic related to web like browsers, html, privacy, security etc.

This book itself has been created in HTML 5 and has both mouse and keyboard navigation enabled. Moreover, after it loads once, you can read it offline.

Written by the chrome team and with beautiful illustrations by Christoph Niemann,this book is a delight to read. Its language is very simple and catchy and users without any technical background can also read it without worrying about technical jargons.

You can read the book at http://www.20thingsilearned.com/. For the lazy below are direct links for chapters.

Cloud Computing
Web Apps
HTML, JS, CSS and more
3d in a Browser
A browser madrigal or old vs modern browsers
Browser Extensions
Synchronizing the Browser
Browsers and Privacy
Malware, Phishing and Security Risks
How modern browsers protect you from malware and phishing
Using web addresses to stay safe
IP addresses and DNS
Validating identities online
Evolving to a faster web
Open Source and browsers
Conclusion: 19 things later