Write jQuery code to change the color and size of all paragraphs
Description: Make the text of all paragraphs blue and set the font size to 18px.
Hint:
- Pass an object to
.css()to set many properties.
HTML of the page
<p>First paragraph</p>
<p>Second paragraph</p>
<p>Third paragraph</p>
Solution
$('p').css({
'color': 'blue',
'font-size': '18px'
});
HTML after the code runs
<p style="color: blue; font-size: 18px;">First paragraph</p>
<p style="color: blue; font-size: 18px;">Second paragraph</p>
<p style="color: blue; font-size: 18px;">Third paragraph</p>
How it works
- The selector
pfinds all three paragraphs, and the method works on every one of them without a loop.
Read CSS Methods.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |