Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

3.3.1. $()

The dollar function ($()) is a specialized wrapper to the standard document.getElementById() DOM method. Like that method, $() returns the element with the given id.

Unlike the DOM method, you can pass more than one argument and $() will return an array with all the requested elements. And if an argument is anything other than a string, it will be passed through directly. As a result, you can safely call $() on a value multiple times. Whether the argument is a string or already a DOM element, the output will be the same. For example:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint