Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to replace the content in the tag by jquery

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Jquery how to replace the content in the tag, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

In jquery, you can replace the content in the tag with the html () method, which returns or sets the contents of the selected element. When no parameters are set using this method, the current content of the selected element is returned with the syntax of "$(element). Html (" new content ").

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How does jquery replace the content in the tag

The html () method returns or sets the content (inner HTML) of the selected element.

If the method does not set a parameter, it returns the current contents of the selected element.

Returns the content of the element

When you use this method to return a value, it returns the contents of the first matching element.

Grammar

(selector) .html ()

Set element content

When you use this method to set a value, it overwrites the contents of all matching elements.

Grammar

$(selector) .html (content)

Content is optional. Specifies the new content of the selected element. This parameter can contain a HTML tag.

Use a function to set the content of an element

Use the function to set the contents of all matching elements.

Grammar

$(selector) .html (function (index,oldcontent))

Function (index,oldcontent) specifies a function that returns the new content of the selected element.

Index-optional. The index location of the receive selector.

Oldcontent-optional. Receives the current contents of the selector.

Examples are as follows:

$(document) .ready (function () {$(".btn1") .click (function () {$("p"). Html ("this is new");})

This is the old content.

This is also the old content.

Change the content of p element

Output result:

After clicking the button:

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report