jquery next() and find() to remove class from element doesn't work for me

cypher75

I'm currently having a problem:

I have different elements in my html. All except the first one having a class called "inactive" and I want them click by click (on each cell) to become active (remove "inactive" attribute).

Clicking the first, will activate the second. Clicking the second, will activate the third. And so on.

Here is my html.

<div class="around">
    <div class="row">
        <div class="cell">text 1</div>
    </div>
    <div class="row inactive">
        <div class="cell">text 2</div>
    </div>
    <div class="row inactive">
        <div class="cell">text 3</div>
    </div>
</div>

here is my jquery (found that on stackoverflow)

$( document ).ready(function() {
    $( ".cell" ).click(function() {
        $(this).closest('.around').next().find('.inactive').removeClass('inactive');
    });
});

This will do... nothing.

I also tried:

$(this).closest('.around').find('.inactive').removeClass('inactive');
    });

But this will remove "inactive" class from all elements

Can anyone help please?

Milind Anantwar

If you want to removeclass from parent of clicked element, You need to traverse to parent element using .parent() :

$( ".cell" ).click(function() {
  $(this).parent().removeClass('inactive');
});

If you want to remove the class from next sibling element of clicked parent, then use .parent() along with .next():

$( ".cell" ).click(function() {
  $(this).parent().next().removeClass('inactive');
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jquery next() and find() to remove class from element doesn't work for me

From Dev

Remove class from next element jQuery

From Dev

JQuery Add/Remove Class doesn't work

From Dev

jQuery: Find next Element with same class

From Dev

jquery find next element with class name

From Dev

Jquery find doesn't work

From Dev

$(this) and find doesn't work in JQuery

From Dev

jQuery remove string from string doesn't work

From Dev

next("some class") doesn't work

From Dev

Php remove catch doesn´t work for me

From Dev

Testing angular directive that remove dom element doesn't work (at least for me...)

From Dev

Getting element by class name with jQuery doesn`t work when element is in ng-repeat directive

From Dev

JQuery syntax - remove() won't work on element

From Dev

jQuery .remove() with selector doesn't work

From Dev

jQuery .remove(Selector) doesn't work

From Dev

jQuery closest() remove() on <a> doesn't work?

From Dev

Find next element in jquery

From Dev

jquery .on() doesn't work for cloned element

From Dev

Changing the ID for an element doesn't work with jQuery

From Dev

Changing the ID for an element doesn't work with jQuery

From Dev

jQuery(".element").scrollTop(0); doesn't work

From Dev

Removing element by EQ filtering doesn't remove the element from jQuery Object

From Dev

JQuery doesn't remove class by internal item

From Dev

Jquery index() doesn't find my element

From Dev

Why my find('a') doesn't work in jquery?

From Dev

Jquery append with find doesn't work together

From Dev

Jquery remove nth class from element

From Dev

Why doesn't doesn't this jQuery remove function work?

From Dev

jQuery closest li with a class doesn't work

Related Related

HotTag

Archive