6

I have a problem to remove only img class from active div :

<div class="thumb thumb-selected">

<img class="img-thumb BWFilter BWfade" src="100x100.jpg" alt=""><img crossorigin="anonymous" style="height: 100px; width: 100px; margin-top: 0px; margin-left: 0px;" class="img-thumb" src="3-100x100.jpg" alt=""></div>

I want to remove (BWFilter BWfade) class, only for this div (.thumb .thumb-selected), I'm trying with this jquery code:

$('.thumb .thumb-selected').find('.img-thumb img').removeClass("BWFilter BWfade");
Mathemats
  • 1,185
  • 4
  • 22
  • 35

7 Answers7

4

the removeClass accepts more then one class to remove:

 $('.thumb.thumb-selected > img.img-thumb').removeClass('BWFilter BWfade');

The > - selector will only match when the img is a direct child of your div.

Reference

.removeClass()

css - child-selector

empiric
  • 7,825
  • 7
  • 37
  • 48
1

Use this. Less code for sure. The first selector will only select the div element having the .thumb AND .thumb-selected class name. Then, .find() function is to get the descendants of each element in the current set of matched elements. For this case, will find out the img tag and remove the .BMFilter and .BWfade class name attached on it.

$('div.thumb.thumb-selected').find('img').removeClass("BWFilter BWfade");
Norlihazmey Ghazali
  • 9,000
  • 1
  • 23
  • 40
1

Consider this jquery line:

$('.thumb.thumb-selected').find('img.img-thumb').removeClass("BWFilter BWfade");

DEMO

Removed space from $('.thumb .thumb-selected').

Reference: How can I select an element with multiple classes?

Community
  • 1
  • 1
Manwal
  • 23,450
  • 12
  • 63
  • 93
0

Try this

$('.thumb-selected').find('.BWFilter').removeClass("BWFilter").removeClass("BWfade");
0

Please use below given JS code

$('.thumb-selected').find('.img-thumb').removeClass("BWFilter").removeClass(' BWfade');
halfer
  • 19,824
  • 17
  • 99
  • 186
Yogesh Sharma
  • 2,017
  • 1
  • 15
  • 33
0

Try This :-

$('div.thumb.thumb-selected').find('img.img-thumb').removeClass("BWFilter BWfade");
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
0

Use this

$('.thumb.thumb-selected').find('img.img-thumb').removeClass("BWFilter BWfade");
I'm Geeker
  • 4,601
  • 5
  • 22
  • 41