Using jQuery add the class " w3r_font_color " to the last paragraph element.
HTML Code :
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-git.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Add a specified class to the matched elements.</title> </head> <body> <p>PHP</p> <p>Java</p> <p>Python</p> </body> </html>
CSS Code:
p { margin: 8px; font-size: 16px; } .w3r_font_color{ color: red; } .w3r_background { background: yellow; }
JavaScript Code :
$( "p" ).last().addClass( "w3r_font_color" );
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
HTML Code :
CSS Code:
JavaScript Code :