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 use jquery to change text by clicking

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

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "how to click to change the text with jquery", the content is detailed, the steps are clear, and the details are handled properly. I hope that this "how to click to change the text with jquery" article can help you solve your doubts.

Implementation method: 1, use the "$(" button ") .click (function () {})" statement, bind the button element to the click event, and set the event handler function; 2, in the handler function, set the "element object .text (" new text ")" or "object .html (" new text ")" statement to modify the text.

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

Using jquery to change text by clicking

1. Set click events

Use click () to bind click events to button elements and set event handlers

$(document) .ready (function () {$("button") .click (function () {/ / code executed after the click event);}) Modify the text content of all p elements

This is a paragraph.

This is another paragraph.

2. In the event handler function, use text () or html () to modify the text content of the specified element

The text () method sets or returns the text content of the selected element.

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

$(document) .ready (function () {$("button") .click (function () {$("p"). Text ("Hello world!");})

$(document) .ready (function () {$("button") .click (function () {$("p"). Html ("Hello!");})

Description:

Html () gets all the content inside the element, while text () only gets the text content

Html () sets content that contains tags, while text () sets only text content (without tags).

$(document) .ready (function () {$("button") .click (function () {$("p"). Html ("Hello world!");})

After reading this, the article "how to click and change text with jquery" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

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