Home > Web Front-end > JS Tutorial > How to replace content in text with jquery

How to replace content in text with jquery

青灯夜游
Release: 2021-11-15 15:06:11
Original
5921 people have browsed it

In jquery, you can use the html() method to replace the content in the text. The function of this method is to return or set the content of the selected element. The syntax is "$(selector).html(content)".

How to replace content in text with jquery

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

In jquery, you can use the html() method to replace the content in the text.

html() method returns or sets the content (inner HTML) of the selected element. If this method does not set parameters, it returns the current content of the selected element.

When using this method to set a value, it will overwrite the content of all matching elements.

Syntax

$(selector).html(content)
Copy after login
  • content: Optional. Specifies the new content of the selected element. This parameter can contain HTML tags.

Example:

<!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <title></title>
      <script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
  </head>
  <style>
   #btnTex{width:0px; height:0px; margin: 0px;}
   
 </style>
 <body>
   
 <input id="text" type="text" />
 <input id="btn" type="button" value="按钮" />
 <p id="p">这是一些文字</p>
     <script  type="text/javascript" charset="utf-">
        $(function(){
               var text = $(&#39;#text&#39;);
               var btn = $(&#39;#btn&#39;);
               var p = $(&#39;#p&#39;);
                btn.click(function(){
                 p.html(text.val());
 
               })
        })
    </script>  
 </body>
 </html>
Copy after login

How to replace content in text with jquery

Related tutorial recommendations: jQuery video tutorial

The above is the detailed content of How to replace content in text with 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template