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 3 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 3 years ago

Answers (1)

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

You can use Below code.

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

 

You can use Below code

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

Kathiriya Pritam replied 3 years ago

Subscribe

Select Categories