jquery查找id高于某个数字的div

don*_*ame 0 jquery

有什么办法可以找到它吗?例如:

var number=5;
$("#"+>number).remove();
Run Code Online (Sandbox Code Playgroud)

但我不知道如何做类似的事情,如果有可能:) 谢谢

the*_*dox 5

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

如果id只包含number.

但是您应该只避免使用 numeric id

例如:

<div id="myid-5"></div>
<div id="myid-6"></div>
Run Code Online (Sandbox Code Playgroud)

并将上面的代码修改为:

$('div').filter(function() {
   return parseInt( this.id.replace('myid-',''), 10) > 5;
}).remove();
Run Code Online (Sandbox Code Playgroud)