简体   繁体   中英

How can I “click” all divs in the firebug console?

How can I perform a "click" action on all the rows that start with "user_" in the following html:

<div id="rows">
  <div id="user_1"></div>
  <div id="user_2"></div>
  <div id="user_3"></div>
  <div id="user_4"></div>
</div>
jQuery('div[id^="user_"]').click();

http://api.jquery.com/attribute-starts-with-selector/

假设“执行单击操作”是指“触发单击事件”,则可以使用属性starts-with选择器,以及不带参数的click方法(等同于trigger("click") ):

$("div[id^='user_']").click();
$("div[id^=user_]")​​​​​​​​​​​​​​.click();

You can paste that inside the Firebug console or just put it in your page as it is valid JavaScript either way.

Live example

Selecting all elements with an attribute starting with some string:

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

"Clicking" them:

$('div[id^="user_"]').click();

However, you might want to add a class to them, which beats string matching on attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM