• Resolved Famke__

    (@famke_)


    Hey everyone,

    I have a problem with jQuery. All the code I type correctly works, except when I call for a “removeClass”.

    So far, I have made a tablestructure. On click, the complete first table needs to have an opacity of 0.5. To ensure this, I added a class called “opacity” to the table. In CSS, I wrote that the class has an opacity of 0.5. This works fine: the complete table gets the correct opacity on click.

    However, the item that was clicked in the table shouldn’t have that opacity. I tried to remove the class from the specific item, but it doesn’t seem to work. It only works when I try to do this for the complete table.

    I hope someone can help me out, here’s the code:

    jQuery('.home_tableClick').click(function(){
    		jQuery('.home_tableEerste').addClass('opacity');
    		jQuery(this).removeClass('.home_tableEerste');
    		jQuery('#home_tableFun').load('wp-content/themes/ctaconsulting/tables.php?category='+jQuery(this).attr('id'));
    		jQuery('.initialHidden').hide();
    		jQuery('.home_tableTweede').show();
    });
Viewing 5 replies - 1 through 5 (of 5 total)
  • jQuery(this).removeClass('.home_tableEerste');

    Try this…

    jQuery(this).removeClass('home_tableEerste');
    Thread Starter Famke__

    (@famke_)

    Thanks! It doesn’t seem to work, though.

    Also, this code:
    jQuery(this).removeClass('home_tableEerste');
    is supposed to be:
    jQuery(this).removeClass('opacity');

    That’s how I intended it at least. I guess I changed it to “home_tableEerste” because I was trying to the problem.

    Still doesn’t work with the opacityclass and without the dot though.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    If you’re having a JS issue then you need to show us the Webpage with the problem

    Thread Starter Famke__

    (@famke_)

    I’m running the website on localhost, so I can’t do that unless I add a screenshot or such.

    Thread Starter Famke__

    (@famke_)

    I decided to try to just add CSS to the table itself, which works. Still, I don’t know how to add CSS to the tableitem that I clicked, and give that item an opacity of 1.0.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘removeClass doesn't work, addClass does’ is closed to new replies.