Home >Web Front-end >JS Tutorial >How to assign value to div in jquery

How to assign value to div in jquery

王林
王林Original
2020-11-26 10:58:225851browse

The method of assigning values ​​​​to divs in jquery: first create the addtext function; then obtain the div object through id (mydiv) within the function; finally use the text method to assign values ​​​​to the div, such as [function addtext(){$( '#mydiv').text('xx')}].

How to assign value to div in jquery

The operating environment of this tutorial: Windows 10 system, jquery version 2.2.4. This method is suitable for all brands of computers.

(Learning video sharing: jquery video tutorial)

The specific method is as follows:

Create a new html file and name it test.html.

How to assign value to div in jquery

In the test.html file, use the div tag to create a module. There is no value in the div. It is mainly used to assign values ​​to the div below.

How to assign value to div in jquery

In the test.html file, set the id attribute of the div to mydiv, which is mainly used to obtain the div object through the id attribute below.

How to assign value to div in jquery

In the test.html file, use the button tag to create a button with the button name "Assign value to div".

How to assign value to div in jquery

In the test.html file, bind the onclick event to the button button. When the button is clicked, the addtext() function is executed.

How to assign value to div in jquery

In the js tag, create the addtext() function. Within the function, use the $ symbol to obtain the div object through id(mydiv), and use the text() method to assign a value to the div. . For example, assign the value to div as "aaabbbccc".

How to assign value to div in jquery

For more programming-related knowledge, please visit: Programming Learning! !

The above is the detailed content of How to assign value to div in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn