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
Example
<html>
<head><script src="http://code.jquery.com/jquery-latest.js"></script> </head>
<body>
<input type='text' />
<textarea > </textarea>
</body>
<script>
$('input[type=text], textarea').css({width: '70%'});
</script>
</html>