For some reason the toggleClass function does not seem to be working.
I have a table row with a class “nodrag” – being used with tableDnD plugin:
<tr id="1" class="nodrag">
<!--Some tds and stuff-->
</tr>
When I click a link I want to toggle the class on and off with the following code which is in the $(document).ready function:
$("#reorder").click(function(event) {
$("#1").toggleClass("nodrag");
if ($(this).text()=='Reorder')
{
$(this).text("Done reordering");
} else {
$(this).text("Reorder");
}
event.preventDefault();
});
I know the click event fires because the text of the link changes. I also know the selection of the row works because if I do something else with it like – $(“#1”).text(“test”) – that works.
It just seems to a problem with toggleClass. I’ve searched everywhere though and found nothing that helps me.
Thanks in advance for any help
this is a live demo that is working perfect for me
http://jsfiddle.net/Yjqkn/
Give it a try and let me know what is different between this code and yours.
P.S:
you should always avoid naming your IDs with plain numbers, if you are inforced to do so, prefix it with any letter(s) before the number ex:TblRow1, txt2. but it’s always recommended to name your controls with meaningful words ex: txtUsername, lnkDelete, etc.