脚本继续窃取删除功能上的类

时间:2012-08-21 09:36:00

标签: jquery html

我有一个脚本,出于功能原因删除了一个类,问题是它删除了所有类,而不仅仅是它应该的类。

HTML

  <ul id="slidecontrols" class="sc-nav">
  <li class="dont-remove">
     <a href="#one" class="user-management shadow1">User Management</a>
  </li>
  <li class="dont-remove">
    <a href="#two" class="asset-management shadow1">Asset Management</a>
  </li>
   <li class="dont-remove">
    <a href="#three" class="reporting shadow1">Reporting & Analytics</a>
  </li>
  </ul>

jQuery正在添加类.selected并删除类.selected与该“li”元素上的所有其他类。

$(document).ready(function () {

//Set the initial state: highlight the first button...
$('#slidecontrols').find('li:eq(0)').addClass('selected');

//and hide all slides except the first one
$('#slides').find('> div:eq(0)').nextAll().hide();

//actions that apply on click of any of the buttons
$('#slidecontrols li').click(function (event) {

    //turn off the link so it doesn't try to jump down the page
    event.preventDefault();

    //un-highlight the buttons
    $('#slidecontrols li').removeClass();

    //hide all the slides
    $('#slides > div').hide();

    //highlight the current button
    $(this).addClass('selected');

    //get the index of the current button...
    var index = $('#slidecontrols li').index(this);

    //and use that index to show the corresponding slide
    $('#slides > div:eq(' + index + ')').show();

});

});

< /script>

1 个答案:

答案 0 :(得分:0)

jsBin demo

而不是:

$('#slidecontrols li').removeClass();

使用:

$('#slidecontrols li').removeClass('selected');