What is JQuery Selectors
In this article I am going to explain about jquery selectors.
jQuery Selector
For work with Html element in jquery selector is must because selection specifies on which element element you want to perform action. Selection element may be single element, several element or all element in document.
Syntax
All selection start as follow.
There are several selection type that are following.
Selectors |
|
Definition |
$("*") |
|
Select all element |
$(this) |
|
Select current html element. |
$("p") |
|
Select all <p> element |
$("#mm") |
|
Select element where id="mm". |
$("mm") |
|
Select <p> element which id="mm". |
$(".cls") |
|
Select element where class="cls". |
$("p.cls") |
|
Select <p> element with class="cls". |
$(":animated") |
|
Select all animation that are currently animated. |
$(":button") |
|
Select all button element. |
$("[:href]") |
|
Select all element with href attribute. |
$("ul li:first") |
|
Select first <li> of <ul> element. |
$("href$.='jpg'") |
|
Select all href attribute that end with .jpg |
Example
In following example selection is $("*"). when we click on button then all element will be hide.
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
$("*").hide();
});
});
</script>
</head>
<body>
<h2>
my Jquery program</h2>
<p>
Hello</p>
<p>
How are you</p>
<button>
Click</button>
</body>
</html>
|
Output
You may also want to read these related articles: here
Ask Your Question
Got a programming related question? You may want to post your question here