0

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+"'>

2 Answers 2

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

Without the period ("."+ part).

edit
An example

Sign up to request clarification or add additional context in comments.

5 Comments

@nikita when I reclick the checkbox the class is not removed, pls check your example again.
@Jean It is removed, check in the firebug or other development tool. Element isn't removed itself, obviously, but class is removed from element.
I want to remove the element.
@Jean Jeez. Could've found it in google: "jquery remove element"
@nikita got the element removed by .remove()
0

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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.