- jQuery - Home
- jQuery - Roadmap
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
jQuery :header Selector
The :header selector in jQuery is used to select all header elements in the HTML document. It targets all header tags including <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>.
Syntax
Following is the syntax of :header selector in jQuery −
$(":header")
Parameters
Following are the parameters of this method −
- ":header" − This selector selects all header elements in the document.
Example 1
In the following example, we are demonstrating the basic usage of :header selector in jQuery −
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(":header").css("background-color", "yellow");
});
</script>
</head>
<body>
<h1>Main Title</h1>
<h2>Subtitle</h2>
<h3>Section Title</h3>
<p>This is a paragraph.</p>
</body>
</html>
When we execute the above program, the :header selector selects all the header elements and highlights them with a yellow background color.
Example 2
In this example, the :header selector is used to add ("highlight") class to all header elements within the document −
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(":header").addClass("highlight");
});
</script>
<style>
.highlight {
background-color: yellow;
}
</style>
</head>
<body>
<h1>Main Title</h1>
<h2>Subtitle</h2>
<h3>Section Title</h3>
<p>This is a paragraph.</p>
</body>
</html>
After executing the above program, the "highlight" will be added to all the header elements in the DOM.
jquery_ref_selectors.htm
Advertisements