Q:

Get the background color of a clicked division using jquery

0

Get the background color of a clicked division using jquery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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);
  });

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now