1

Can I remove a class property in html using jquery?

If the element is class = "item active" on the next clone in jQuery how can I remove the active word?

Here's the Jquery Code

(function() {

  $('#itemslider').carousel({
    interval: 3000
  });
}());

(function() {
  $('.carousel-showmanymoveone .item').each(function() {
    var itemToClone = $(this);
    var allcase = $('#cases').val();

    for (var i = 1; i < allcase - 1; i++) {
      itemToClone = itemToClone.next();


      if (!itemToClone.length) {
        itemToClone = $(this).siblings(':first');
      }


      itemToClone.children(':first-child').clone()
        .addClass("cloneditem-" + (i))
        .appendTo($(this));
    }
  });
}());
3
  • 2
    .clone().removeClass('active') Commented Apr 11, 2017 at 15:24
  • look at removeClass() function Commented Apr 11, 2017 at 15:24
  • thank you everyone, yes i did try that code before i asked but i don't know where to place it hahaha Commented Apr 11, 2017 at 15:35

3 Answers 3

2

you should use removeClass method

$(".active").removeClass("active");
Sign up to request clarification or add additional context in comments.

1 Comment

No need the dot inside removeClass('active').
0

$("#your-element-id").removeClass('the-class-you-want-to-remove')

Example:

// Try to comment this line
$("#my-div").removeClass('active');
.active{
  background-color: grey;
}
.blue{
  color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="my-div" class="item active blue">Hello, World!<div>

Comments

0

You can use the jQuery.attr function to set the new class.

jQuery('selector').attr('class', 'item');

1 Comment

Good, but this will remove other classes. Ex: class="item active blue", When use your method this witll be class="item". note that blue class was removed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.