jQuery的所有具有相似ID的所有元素

问题描述:

页面上有很多元素-ID1, ID2 ID3 ...

我想操纵所有元素.有没有更简单的方法可以做到这一点.

I want to manipulate all the elements. Is there any simpler way to do this.

$("#ID").each(function(){ ... });

您可以使用^选择器.

示例

$('div[id^="ID"]')

^=选择ID属性以ID开头的DOM(即ID1,IDID,IDS,ID2等)

^= select DOM whose ID attribute starts with ID (i.e ID1, IDID,IDS,ID2 etc)