I am working with jquery and attempting to add a class to a table on the selection of that table row.
I was initially using the following code -
$(this)
If addClass
is working for you, then you should stick with it. The methods are meant for different purposes. addClass
ensures that a particular class is present on an element, while toggleClass
adds the class if it isn't there and removes it if it is.
Check out the API reference for the full explanation of each method: