Tuesday, September 13, 2011

How can you select various HTML Elements using jQuery?


jQuery can be used to select HTML elements using element selector. Below are some of the examples of how to use selectors.
  • $(<’element>’)  - Selects all elements with the given tag name.
  • $(‘p’) – Selects all  Paragraph  Elements
  • $(‘a’) – Selects all Anchor tags in side a web page
  • $(‘I’)  - Selects all Italic tags in the webpage
  • $(‘input[type=text]’) – Selects all textboxes in side a webpage
After selection we can call methods .

Selecting multiple elements
$(‘p,a,div,span’) – Selects all p, a, div, span elements in the web page.
<script>$("p").after( $("b") );</script>
The above script selects all p and makes the content after <p> tag as bold.

Selecting all the elements
$(‘*’) – This will select all html elements in web form

No comments:

Post a Comment