Logo
  Sunday, May 20, 2012
Sign-In  |  Sign-Up  |  Contact Us  | Bookmark |  RSS Feed

HTML5 Tutorial FeedBurner

HTML5 Selectors API   
HTML5 makes it easier to find HTML5 elements on the page or within your DOM structure. List of available calls and Descriptions with the examples are listed below.

First, you can get element by referencing its DOM id. This is done with the help of function called:

getElementById()

It returns the element by its ID. Example of this function call is

<div id="myId">


getElementById("myId");

Another function call is somewhat similar to first, but instead of ID it looks for DOM element by name. AS a result, it is called:

getElementsByName()

Returns elements of the page where name is specified as this function argument

<input  type="text" name="myId">


getElementsByName("myId");

Finally, you can find and return element by its tag ame. getElementsByTagName()

Return all elements whose tag name matches the specified value

<input type="text">


getElementsByTagName("input"); There are other selectors worth mentioning. They are called QuerySelectors. There are two of them. First is called querySelector() and another querySelectorAll(). First query selector returns first element which is found based on the search criteria and second is used to return all instances of the items matching its search criteria.

Example: var x = document.querySelector(".myClass") //returns first instance of the item with style called .myClass applied against it.

Print HTML5 Selectors API  Bookmark HTML5 Selectors API

Related Articles  
HTML5 History
HTML5 goes back to 1993 when it was first published as internet draft. It evolved through such important milestones as ...
HTML5 plug-ins
HTML5 is built to be versatile enough so that third party plug-ins would not be required. HTML5 nativly supports many ...
HTML5 new elements
HTML5 has many more HTML markup elements. These markup elements are grouped into content types for easy access and ...
HTML5 design principles
The main objective of HTML5 is not degrading any of the existing content on the internet. There is over 20 years of ...
HTML5 Sectioning content type
Sectioning is a new semantic markup to define sections on the page. It is mainly used as future expansion of HTML5 ...
Welcome to www.html5videotutorial.com
Learn HTML5 development techniques, tips and tricks on our website. Find out what is required to develop web pages to ...
More