In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about whether you can add styles with jquery. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Use jquery can add style, method: 1, use "$(element). Attr (" style "," inline style code ")" statement; 2, use "$(element) .css ({" attribute name ":" attribute value "})" statement; 3, use "$(element) .addClass (" class name ") statement.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, there are several ways to add styles to elements, here are a few:
Method 1: add inline styles using the attr () method
$(document) .ready (function () {$("button") .click (function () {$("p") .attr ("style", "border: 2px solid green; background-color: # 55aa7f 2px solid green; background-color: white;");})
Hello, test text
Add Styl
Method 2: use the css () method
The css () method returns or sets one or more style properties of the matching element.
$(document) .ready (function () {$("button") .click (function () {$("p") .css ({"border": "1px solid red", "background-color": "# FFC0CB", "color": "white"});})
Hello, test text
Add Styl
Method 3: use the addClass method
The addClass () method adds one or more classes to the selected element.
$(document) .ready (function () {$("button") .click (function () {$("p"). AddClass ("intro");}) .intro {font-size: 120%; color: red;}
Hello, test text
Add Styl
Thank you for reading! This is the end of the article on "whether you can add style with jquery". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.