jQuery > Tips
Contents
Tips
buggy behavior 325
updated 15d ago
with scrollTop.
Chain Plugin Calls
jQuery allows for the "chaining" of plugin method calls to mitigate the process of repeatedly querying the DOM and creating multiple jQuery objects. Let's say the following snippet represents your plugin method calls: ``javascript $("#elem").show(); $("#elem").html("bla"); $("#elem").otherStuff(); ` This could be vastly improved by using chaining: `javascript $("#elem").show().html("bla").otherStuff(); ` An alternative is to cache the element in a variable (prefixed with $): `javascript var $elem = $("#elem"); $elem.hide(); $elem.html("bla"); $elem.otherStuff(); `` Both chaining and caching methods in jQuery are best practices that lead to shorter and faster code.