Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement chain plug-in call by jQuery

Shulou Source: shulou.com Published: 2022-06-01 04:51:10 09月17日 Update

This article is about how jQuery implements chained plug-in calls. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Chain plug-in call

JQuery allows method calls from "chained" plug-ins to ease the process of repeatedly querying DOM and creating multiple jQuery objects. For example, the following code snippet represents your plug-in method call:

$('# elem'). Show (); $('# elem'). Html ('bla'); $(' # elem'). OtherStuff ()

By using chaining, it can be greatly improved:

$('# elem'). Show (). Html ('bla'). OtherStuff ()

Another way is to cache elements in the (prefix $) variable:

Var $elem = $('# elem'); $elem.hide (); $elem.html ('bla'); $elem.otherStuff ()

Chained and cached approaches are both best practices in jQuery to make code shorter and faster.

Thank you for reading! This is the end of this article on "how to implement chain plug-in calls in jQuery". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Chained plug-ins methods code content more articles caching high-speed good practical representatives practices elements prefixes variables multiple objects articles are in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info Xiaomi Linux OPPO Reno