简体   繁体   中英

Change multiple glyphicons with one click

I am using Bootstrap glyphicons as checkboxes for multiple nodes on a folder tree. I need to toggle all glyphicon checkboxes for a given folder (but ONLY THIS folder and ONLY CHECKBOXES) when said folder's checkbox is clicked.

<li data-layerid="Analises" data-grouped="group_Analises" class="parent_li">
  <span title="Collapse this branch"><i class="glyphicon glyphicon-file"></i> Analises</span>
  <i class="glyphicon glyphicon-unchecked" id="group_Analises" data-foldername="group_Analises"></i></li>

<li data-layerid="V%" data-grouped="2014">
  <span><i class="glyphicon glyphicon-file glyphicon-check"></i> V%</span>
  <i class="glyphicon glyphicon-check" id="2014" data-foldername="2014"></i> 
</li>
<li data-layerid="Ca" data-grouped="2014">
  <span><i class="glyphicon glyphicon-file glyphicon-check"></i> Ca</span>
  <i class="glyphicon glyphicon-check" id="2014" data-foldername="2014"></i> 
</li>

If I do this, I change all glyphicons on the page.

$('i').removeClass('glyphicon-check').addClass('glyphicon-unchecked');

在此处输入图片说明

If I attempt to access the id directly, I only manage to change the first element with this id, not all of them:

$('#2014').removeClass('glyphicon-check').addClass('glyphicon-unchecked');

在此处输入图片说明

Suggestions VERY welcome.

尝试删除DOM上的id属性,而改用data-foldername属性。

$('i[data-foldername="2014"]').removeClass('glyphicon-check').addClass('glyphicon-unchecked');

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