Jquery selectors

Google Advertisements

Prev Tutorial Next Tutorial

Selectors

jQuery selectors are used to find or select Html elements based on their id, classes, types, attributes, values of attributes etc.. This jQuery selector is based on css selector but it have some own custom selectors.

Selector in jQuery is start with $ sign and parentheses: $()

Syntax

$(selector).action()

Element Selector

jQuery element selector selects or find Html elements based on the element name. In below syntax you can select all <p> elements.

Syntax

$("p")

Example of element selector

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").hide();
    });
});
</script>
</head>
<body>

<h2>jQuery Code</h2>

<p>This is My first jQuery code</p>

<button>Click me</button>

</body>
</html>

Output

jQuery Code

This is My first jQuery code

#id Selector

jQuery id selector finds elements with a specific id. In below syntax you can find or select all elements which have list id.

Syntax

$("#list")

Example of #id selector

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#list").hide();
    });
});
</script>
</head>
<body>

<h2>jQuery Code</h2>

<p id="#list">This is My first jQuery code</p>

<button>Click me</button>

</body>
</html>

Output

jQuery Code

This is My first jQuery code

.class Selector

jQuery class selector finds elements with a specific class. In below syntax you can find or select all elements which have list class.

Syntax

$(".list")

Example of .class selector

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $(".list").hide();
    });
});
</script>
</head>
<body>

<h2>jQuery Code</h2>

<p id=".list">This is My first jQuery code</p>

<button>Click me</button>

</body>
</html>

Output

jQuery Code

This is My first jQuery code

Examples of jQuery Selectors

  • $("*") : Selects all elements.
  • $(this) : Selects the current Html element.

Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs