Professional Documents
Culture Documents
jQuery
jQuery Selectors
The Document Object Model (DOM) is a programming interface for web documents. It
represents the page so that programs can change the document structure, style, and content.
The DOM represents the document as nodes and objects; that way, programming languages can
interact with the page.
03/09/2024 2
What is $(document).ready(function(){} )
03/09/2024 3
jQuery Selectors
jQuery selectors allow you to select and manipulate HTML element(s).
jQuery selectors are used to "find" (or select) HTML elements based on their
name, id, classes, types, attributes, values of attributes and much more. It's
based on the existing CSS Selectors, and in addition, it has some own custom
selectors.
All selectors in jQuery start with the dollar sign and parentheses: $().
03/09/2024 4
jQuery Selectors
jQuery Selectors can find HTML elements (ie. Select HTML elements) based on the
following:
03/09/2024 5
jQuery Selectors
03/09/2024 6
Example #1
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>1st paragraph.</p>
<p>2nd paragraph.</p>
<button>Click to hide all paragraphs</button>
</body>
</html>
03/09/2024 7
03/09/2024 8