Forums

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

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #37681

    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

    #101446

    EDIT: removed as it didn’t answer the question.

    #101449
    Senff
    Participant

    @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/ )

    #101459
    StevenBullen
    Member

    This is because hasClass returns True/False so you’re not using the initial object anymore.

    #101461
    jamygolden
    Member

    Try this:

    $('.custom-sidebar').filter(function(){
    return $(this).hasClass('textwidget');
    }).removeClass('bkp-frame-wrapper');

    http://jsfiddle.net/fK6wE/2/

    #101437

    @Senff Right, it pays to read the question correctly…

    #101497

    Thanks for all the help guys.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.