Search code examples
jqueryhtmlfindremoveclass

Jquery remove() not works with removeClass()


I have a span which consist of 6 divs(4 resize, 1 rotate, 1 property box)

The following functionality i need when onclick button:

  1. I need to removeClass() for first five(4 resize, 1 rotate) classes. - Works perfectly
  2. I need to remove() last div (1 property box). - Not working

How to remove the last div from the span..? Please help me. Thanks in Advance...

Code which i used:

$(document).ready(function() 
{
    $('button').on('click', function() 
    { 
        $('.workspace > span').find('div').removeClass();
        $('.workspace > span').find('div').eq(6).remove();
    });
});

My code in JSfiddle..!


Solution

  • Instead of

    $('.workspace > span').find('div').eq(6).remove();
    

    Use(instead of eq(6) try eq(5))

    $('.workspace > span').find('div').eq(5).remove(); //eq indexing starts from 0.
    

    Updated Fiddle

    Docs