weixin_33728268 2012-01-05 22:21 采纳率: 0%
浏览 14

原型js库初学者

I have a list in which I am dynamically adding the classname, now when I click on that item again the class stays there. I dont want that I want that classname to be assigned to the currently clicked list item.

<ul id="menubar">

<li>one</li>
<li>two</li>
</ul>

Now when I click on one I dynamically add classname, and when I click on two the classname stays the same on one and it gets affected on two as well. but I want it to be removed from one and to be applied to currently clicked item.

How can I achieve it?

  • 写回答

2条回答 默认 最新

  • weixin_33724059 2012-01-05 22:27
    关注

    You need to be including .removeClass() in the same event as when you addClass() to the other one.

    $('.one').click(function(){
      $(this).addClass('myClass');
      $('.two').removeClass('myClass');
    });
    

    This could be written more efficiently, but im writing this in between meetings.

    Hope it's a start!

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧