Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Set the Value of a CSS Property</title> <style> .box{ width: 100px; height: 100px; margin: 10px; cursor: pointer; border: 1px solid #cdcdcd; display: inline-block; } </style> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $(".box").click(function(){ $(this).css("background-color", "blue"); }); }); </script> </head> <body> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <p><strong>Note:</strong> Click inside the empty box to fill the background color.</p> </body> </html>