Sangram Anand
Sangram Anand

Reputation: 10854

Jquery removeClass method

I have main div with an ID of mvrContentFormDiv. Inside there, there are 4 child div's with IDs of reportFileURL, UploadReportDate, reportTitle & reportImageURL.

Each of these have a class of error. Right now I am removing that class individually using the following code, but would like to use removeClass from the parent DIV.

$("#reportFileURL").removeClass("error");
$("#uploadReportDate").removeClass("error");
$("#reportTitle").removeClass("error");
$("#reportImageURL").removeClass("error");

Can anyone explain how I can do this?

Upvotes: 1

Views: 537

Answers (5)

Bart Groenhuizen
Bart Groenhuizen

Reputation: 296

Try this:

$("#mvrContentFormDiv").children().removeClass("error");

Upvotes: 1

Darren
Darren

Reputation: 70728

$("#mvrContentFormDiv .error").removeClass("error");

Upvotes: 1

Arthur Neves
Arthur Neves

Reputation: 12128

try something like that:

$("#mvrContentFormDiv div").removeClass("error");

being 'mvrContentFormDiv' your parent id

Upvotes: 2

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123397

unless you have other elements with that class elsewhere in the document that have to be untouched, you could simply do

$('.error').removeClass("error");

otherwise

$('<parentelement> .error').removeClass("error");

Upvotes: 3

Matt
Matt

Reputation: 75317

You could use the children() method or child selector to select them from the mvrContentFormDiv:

$('#mvrContentFormDiv > .error').removeClass('error');

or

$('#mvrContentFormDiv').children('.error').removeClass('error');

Upvotes: 5

Related Questions