Get the background color of a clicked division using jquery
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>Get the background color of a clicked division.</title> </head> <body> <div style="background-color:blue;"></div> <div style="background-color:rgb(15,99,30);"></div> <div style="background-color:#123456;"></div> <p></p> </body> </html>
CSS Code :
div { width: 50px; height: 50px; margin: 5px; float: left; }
JavaScript Code :
$( "div" ).click(function() { var color = $( this ).css( "background-color" ); $('p').html(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 :