1

I have the following jQuery code:

Working code

$( '.spanspec:gt(49)' ).remove();

This removes all checkboxes in my code with the class spanspec where the index is greater than 49. Works fine.

Non-working code

$( '.spanspec:between(41, 46)' ).remove();

What I would like to achieve is to remove multiple checkboxes that have an index between two values. I have tried the above but this does not work.

Please note that I am familiar with the use of :gt :lt :eq but using these in this instance does deliver the desired result.

Any help, advice or feedback would be appreciated.

2 Answers 2

3

Use .slice():

$('.spanspec').slice(41,46).remove();

Here's a smaller, generic jsFiddle example. Note that the range in slice() is zero based, and will go up until (but not including) the index of the second parameter.

Sign up to request clarification or add additional context in comments.

1 Comment

That is perfect and exactly what I was looking for in terms of the final results. Thank you, very much appreciated.
1

I think it should do the work

$('.spanspec:gt(41):lt(46)').remove();

also you can try something like:

$('.spanspec').slice(41, 46).remove();

1 Comment

Thanks for this - .slice(): gives me the desired result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.