jQuery Tutorial Tutorials - jQuery :header selector

:header selector

The :header selector selects all heading elements like h1,h2...h6.

jQuery :header selector Syntax
$(':header')
selector description
$(':header') selects all the headers
$('h1') selects all h1 headers
$('h2') selects all h2 headers
jQuery :header selector Examples

Following is a simple example which makes use of header selector.
This would select all the headers and add a background color to them.

<h1>Header 1</h1>
<p>contents</p>
<h2>Header 2</h2>
<p>contents</p>
<h3>Header 3</h3>
<p>contents</p>
<script>
$(":header").css("background",'coral');
</script>

Try now

Only hightlight the header 2

<h1>Header 1</h1>
<p>contents</p>
<h2>Header 2</h2>
<p>contents</p>
<h3>Header 3</h3>
<p>contents</p>
<script>
$("h2").css("background",'coral');
</script>

Try now

Date:2019-08-18 01:54:04 From:www.Lautturi.com author:Lautturi