tags:

views:

51

answers:

2

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

+3  A: 
$("#"+it0).removeClass(ip1);

Without the period ("."+ part).

edit
An example

Nikita Rybak
For some reason its not working
Jean
@nikita when I reclick the checkbox the class is not removed, pls check your example again.
Jean
@Jean It is removed, check in the firebug or other development tool. Element isn't removed itself, obviously, but class is removed from element.
Nikita Rybak
I want to remove the element.
Jean
('#id').remove(class) does not seem to work either :(
Jean
@Jean [Jeez](http://api.jquery.com/remove/). Could've found it in google: "jquery remove element"
Nikita Rybak
@nikita got the element removed by .remove()
Jean
thanks...........I knew the syntax, at times it does not strike ASAP
Jean
A: 

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"&gt;&lt;/script&gt;
</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/

Tarek El-Mallah