I know that it's not necessary to check if an element has a class before re-adding it with .addClass()
:
https://stackoverflow.com/a/7403519/231914
But what about other jQuery actions?
Do I need to check if something is visible before I call .show()
?
Do I need to check if something already has the text "FooBar" before calling .text('FooBar')
?
In other words, if performance is important should I make a check before performing some action if that action might not actually change anything?
In most cases it probably doesn't matter much. But I'm building a callback for window.scroll so performance is key.