You are looking for :nth-child : http://api.jquery.com/nth-child-selector/
It works as follows:
$('.control div:nth-child(2), .control div:nth-child(3), .control div:nth-child(4)').remove();
Note that :nth-child uses unidirectional indexing, so the first element has index 1.
UPDATE: In response to this question, OP is posted in a comment
If I do not know how many divs will occur after entering the field in any way CUT or SLICE of all divs or any elements that occur after the second child DIV control ...
The answer is yes, for this you want a selector :gt: :: http://api.jquery.com/gt-selector/
$('.control div:gt(1)').remove()
Unlike :nth-child :gt uses indexing with a zero index, so the first element has index 0.
Ben lee
source share