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

Can you add styles with jquery?

2025-01-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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report