Get the App
SLTechnology News&Howtos  ›  Development  › 

What does add mean in jquery

Shulou Source: shulou.com Published: 2022-05-31 20:40:55 09月10日 Update

This article mainly introduces "what does add refer to in jquery". In daily operation, I believe that many people have doubts about what add refers to in jquery. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what does add mean in jquery?" Next, please follow the editor to study!

Add, which means "add", is a built-in method to add an element to an existing combination of elements, with the syntax "$(element) .add (element,context)"; this method accepts two parameters, specifying the element to be added and the location to be added, the second parameter is optional, and if set, the element is only added inside the context element.

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, add means "add".

The add () method adds an element to an existing combination of elements.

This method accepts two parameters, specifying the element to be added and the location to add:

$(selector) .add (element,context)

Element: required. Specifies selector expressions, jQuery objects, one or more elements, and HTML fragments to be added to an existing collection of elements.

Context: optional. Specifies where the selector expression starts to match in the document.

The add () method adds the element to the entire document, or only inside the context element if the context parameter is specified.

Example 1: use a HTML fragment to add an element to an existing

Element.

$(document) .ready (function () {$("button") .click (function () {$("p") .add ("

A new span element. ") .appendTo (" p ");}); add a span element

A P element.

Example 2: put

And elements to an existing combination of elements ():

$(document) .ready (function () {$("H2"). Add ("p"). Add ("span"). Css ("background-color", "yellow"); welcome

A P element.

Another P element.

A span element. A span element.

This example adds the same CSS style p and span elements to the existing H1 element.

At this point, the study of "what does add refer to in jquery" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Elements methods parameters learning location examples combinations upper and lower context two meaning document more fragments expressions help selection utility same next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Microsoft Linux macOS Shulou Technology