How to find all h1 and add a class to it using Jquery

Forums jQueryHow to find all h1 and add a class to it using Jquery
Staff asked 2 years ago

I have to find all h1 tags in a html page and add a class which has color red to them

My class is ass follows:

.error{

color:red;

}

jQuery(‘h1’).addClass(“error”);

Tarun Thummar replied 2 years ago

Answers (1)

Add Answer
Tarun Thummar Marked As Accepted
Staff answered 2 years ago

You can use Below code.

jQuery('h1').addClass('error');

 

You can use Below code

$(“body”).find(“h1”).addClass(‘error’)

Kathiriya Pritam replied 2 years ago

Subscribe

Select Categories