I need to update the class below dynamically using Jquery.
<tr id='myID' class="size colour"> <td></td> </tr>
I tried to use below:
$(“#myID”).toggleClass();
It doesn’t seem to work since my class name is “size colour”. Since the class name is dyanmic I could not use removeClass. Could someone help me please.
Thank you.
Your classname is not
size colourbut your element has two classes,sizeandcolour– these are independent of each other.toggleClass()without any argument removes any currently present classes, so in your casewould remove both classes,
sizeandcolour. On the second call all these classes will be added again.If this is what you intended it to do, then it should work fine and the error is elsewhere. Else you have to clarify what exactly you want to achieve.