X10nD
X10nD

Reputation: 22050

remove class - jquery

I want to remove this class on checkbox toggle.

$("#checkbox").toggle(function () {
    var it0 = $('#IT0').text();
    var ip1 = $('#sv1').text();

    var TC = "<div class='" + ip1 + "' id='" + it0 + "'><input type='text' name='test' value='" + ip1 + "'></div>";

    $('#selected').html(TC);
}, function () {
    var it0 = $('#IT0').text();
    var ip1 = $('#sv1').text();
    $("#" + it0).removeClass("." + ip1);
});

I am not sure why the remove class is not working on "<div class='"+ip1+"' id='"+it0+"'>

Upvotes: 0

Views: 385

Answers (2)

Tarek El-Mallah
Tarek El-Mallah

Reputation: 4115

no need for the dot ".", see below example from jquery APIs Documentation

Remove the class 'blue' from the matched elements.

<!DOCTYPE html>
<html>
<head>
  <style>

  p { margin: 4px; font-size:16px; font-weight:bolder; }
  .blue { color:blue; }
  .under { text-decoration:underline; }
  .highlight { background:yellow; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <p class="blue under">Hello</p>
  <p class="blue under highlight">and</p>
  <p class="blue under">then</p>

  <p class="blue under">Goodbye</p>
<script>$("p:even").removeClass("blue");</script>

</body>
</html>

http://api.jquery.com/removeClass/

Upvotes: 0

Nikita Rybak
Nikita Rybak

Reputation: 68046

$("#"+it0).removeClass(ip1);

Without the period ("."+ part).

edit
An example

Upvotes: 4

Related Questions