In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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 "jquery how to change id with click", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "jquery how to change id with click" can help you solve your doubts.
Methods: 1, the use of "element object .click (function () {event handling function})" to add click events to the specified element, and specify the event handling function; 2, in the event handling function, the use of "element object .attr (" id "," changed id value ");" set the changed id value.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How to change id with click in jquery
Bind the click event to the element
The click event occurs when an element is clicked.
The click () method triggers the click event, or specifies the function to run when the click event occurs.
Grammar
The click event that triggers the selected element:
(selector) .click ()
Add a function to the click event:
$(selector) .click (function)
Second, change the id value by attr method
The attr () method sets or returns the properties and values of the selected element.
When the method is used to return a property value, it returns the value of the first matching element.
When this method is used to set property values, one or more attribute / value pairs are set for matching elements.
Set properties and values:
$(selector) .attr (attribute,value)
Examples are as follows
(document) .ready (function () {$("button") .click (function () {$("div"). Attr ("id", "mydiv2");});}); # mydiv1 {background:#66ccff;} # mydiv2 {background:pink;}
Change the id attribute for the element
Output result:
Read this, the "jquery how to use click to change id" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, 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.
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.