Jquery Toggle() Method
Solution 1:
The "Not recommended. Use .toggleClass() instead" comment is about the provided example, which toggles a class using .toggle()
, it's not a general comment about .toggle()
.
The docs also state why it is not recommended to use:
The .toggle() method is provided for convenience. It is relatively straightforward to implement the same behavior by hand, and this can be necessary if the assumptions built into .toggle() prove limiting. For example, .toggle() is not guaranteed to work correctly if applied twice to the same element. Since .toggle() internally uses a click handler to do its work, we must unbind click to remove a behavior attached with .toggle(), so other click handlers can be caught in the crossfire. The implementation also calls .preventDefault() on the event, so links will not be followed and buttons will not be clicked if .toggle() has been called on the element.
Solution 2:
Because in future versions of jQuery .toggle()
won't be there for you to call and will error out in your code.
Post a Comment for "Jquery Toggle() Method"