用新类替换类

时间:2017-04-27 14:04:15

标签: javascript jquery css css3

我在替换类时遇到问题,我想用jquery或java脚本替换类。我需要更改ul标签内的类。我怎么能改变它

 <ul  id="user-listview" class="userlist" data-bind="foreach:Items">
    <li>
   <span id="spname" data-bind="text:userName"  class="c-user"/><span>
   <div>
      <img id="imguser" data-bind="attr: { src:userImageUrl }" class="c-image" />
     </div>
   </li>
  </ul>

 // I am trying like below code but its doesn't work
  $(".userlist li #spname").removeClass('c-user').addClass('IPuser');
  $(".userlist li #imguser").removeClass('c-image').addClass('IPimage');

1 个答案:

答案 0 :(得分:0)

window.document.getElementById("myId").classList.add("myNewClass");

如果你想删除上一节课:

window.document.getElementById("myId").classList.remove("myOldClass");