- This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
Viewing 7 posts - 1 through 7 (of 7 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Removing a class if it has a certain class
What im trying to do is remove a class if there is a certain class inside of it. I am customizing a wordpress theme and for text widgets I dont want a certain class. Here is what I have so far with jquery but it doesnt seem to work for me. I am kinda new to jquery. So cut me some slack.
$(document).ready(function() {
// do stuff when DOM is ready
if ($(".custom-sidebar).hasClass("textwidget")) {
$.RemoveClass('bkp-frame-wrapper');
}
});
I may have a syntax error, or I could be way off. But what I want is:
if .custom-side has a class of textwidget inside then RemoveClass bkp-frame-wrapper
thanks for any help guys
EDIT: removed as it didn’t answer the question.
@joshuanhibbert That checks if the .custom-sidebar
has the class textwidget
, not if it contains an element with the class textwidget
, no?
I thought it was the latter; check if the sidebar contains a textwidget, and if it does, remove the class from the sidebar. For that I would use this:
$('.custom-sidebar .textwidget').parent().removeClass('bkp-frame-wrapper');
(also, that aside, @joshuanhibbert, I can’t get your code to work, what am I missing?! http://jsfiddle.net/senff/fK6wE/1/ )
This is because hasClass returns True/False so you’re not using the initial object anymore.
Try this:
$('.custom-sidebar').filter(function(){
return $(this).hasClass('textwidget');
}).removeClass('bkp-frame-wrapper');
@Senff Right, it pays to read the question correctly…
Thanks for all the help guys.