In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge of this article "jquery how to add and delete attributes", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to add and delete attributes in jquery" article.
In jquery, you can use attr () or prop () to add attributes to the element, syntax "object .attr (" attribute name "," value ") or" object .prop ("attribute name", "value") "; you can use removeAttr () to delete attributes, and syntax" object .removeAttr ("attribute name") ".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
The method of adding and deleting attributes in jquery
1. Add attributes using attr () or prop ()
Both prop () and attr () can be used to set the HTML attribute of an element.
Example 1: add the disabled attribute using attr ()
$(document) .ready (function () {$("button") .click (function () {$("textarea") .attr ("disabled", "disabled"); / / $("textarea") .attr ("disabled", "true") );})
Make textarea uneditable
Example 2: add the readonly attribute using prop ()
$(document) .ready (function () {$("button") .click (function () {$("input"). Attr ("readonly", "readonly");}) .intro {font-size: 120%; color: red;} add a read-only attribute to input
2. Delete attributes using removeAttr ()
The removeAttr () method removes attributes from the selected element.
Example: use removeAttr () to delete the hidden attribute
The hidden attribute specifies that the element is hidden. Hidden elements are not displayed.
Delete the attribute to make the element display.
(function () {$("button") .click (function () {$("p"). RemoveAttr ("hidden");}))
This is a visible paragraph.
This is a hidden paragraph that is now shown.
This is a visible paragraph.
Delete hidden attribute
The above is about the content of this article on "how to add and delete attributes in jquery". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.