0

is there any way to find it? for example:

var number=5;
$("#"+>number).remove();

but I dont know how do something like it and if is it posibble :) thanks

Charles
  • 50,943
  • 13
  • 104
  • 142
dontHaveName
  • 1,899
  • 5
  • 30
  • 54
  • possible duplicate of [Filtering if a custom selector is greater than a number in jQuery](http://stackoverflow.com/questions/10356765/filtering-if-a-custom-selector-is-greater-than-a-number-in-jquery) – Esailija Jun 26 '12 at 16:53
  • 2
    You should avoid numeric id. They cause problems, both for CSS and Javascript. – Guffa Jun 26 '12 at 16:54
  • Possible duplicate of [jQuery: Selecting all elements where attribute is greater than a value](http://stackoverflow.com/questions/2613648/jquery-selecting-all-elements-where-attribute-is-greater-than-a-value) – Jason C Jul 18 '16 at 20:42

2 Answers2

5
$('div').filter(function() {
  return parseInt( this.id, 10) > 5;
}).remove();

If id contains only number.

But you should avoid only numeric id.

For example:

<div id="myid-5"></div>
<div id="myid-6"></div>

And modify above code as:

$('div').filter(function() {
   return parseInt( this.id.replace('myid-',''), 10) > 5;
}).remove();
Community
  • 1
  • 1
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
0

You can do it with help of the slice function

Reduce the set of matched elements to a subset specified by a range of indices.

See http://api.jquery.com/slice/

This approach will help you get rid of the numerical indices

See my example on jsfiddle

Vladimir Posvistelik
  • 3,843
  • 24
  • 28