JQuery adds a class style to multiple different elements
This article mainly introduces jQuery's method for adding class styles to multiple different elements. The example analyzes the addClass () method's techniques for adding styles, which is very useful. For more information, see
This example describes how jQuery adds class styles to multiple different elements. Share it with you for your reference. The specific analysis is as follows:
JQuery can use the addClass () method to add the same class to multiple different html elements at the same time.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<! DOCTYPE html> <Html> <Head> <Script src = "js/jquery. min. js"> </Script> <Script> $ (Document). ready (function (){ $ ("Button"). click (function (){ $ ("H1, h2, p"). addClass ("blue "); $ ("Div"). addClass ("important "); }); }); </Script> <Style type = "text/css"> . Important { Font-weight: bold; Font-size: xx-large; } . Blue { Color: blue; } </Style> </Head> <Body> <H1> Heading 1 <H2> Heading 2 <P> This is a paragraph. </p> <P> This is another paragraph. </p> <Div> This is some important text! </Div> <Br> <Button> Add classes to elements </button> </Body> </Html> |
I hope this article will help you with jQuery programming.