Home  >  Article  >  Web Front-end  >  jQuery gets content and attributes methods and examples_jquery

jQuery gets content and attributes methods and examples_jquery

WBOY
WBOYOriginal
2016-05-16 17:11:031386browse
Get content - text(), html() and val()

Three simple and practical jQuery methods for DOM operations:

text() - Settings Or return the text content of the selected element
html() - Set or return the content of the selected element (including HTML tags)
val() - Set or return the value of the form field

Get attributes - attr()

jQuery attr() method is used to get attribute values.

The following example demonstrates how to get the value of the href attribute in the link:

Example
Copy code The code is as follows:

$("button").click(function(){
alert($("#w3s").attr("href"));
});
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