How to assign value to div in jquery

王林
Release: 2020-11-30 11:41:03
Original
5698 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!