I am struggling to adjust the color of a transparent image within a div using jQuery. I am facing difficulties in keeping the image aligned within the div while changing its color.
Can someone provide assistance? My goal is to have the image filled upon a user clicking on any of the span colors.
custom-styles.css:
.iconWrapper .color span
{
width: 50px;
height: 58px;
display: block;
}
.color1
{
background-color: #f6f6f6;
}
.color2
{
background-color: #ffe25b;
}
.color3
{
background-color: #e35990;
}
.color4
{
background-color: #58c1d8;
}
step1.php
<link rel="stylesheet" type="text/css" href="custom-styles.css" media="screen" />
<script language="javascript" type="text/javascript">
$(function() {
$('.iconWrapper span').click(function(e){
var color=$(this).attr('class');
//alert(color);
$('#div1').removeClass().addClass(color);
$('#hiddencolor').val(color);
e.preventDefault();
});
});
</script>
</head>
<body>
<div class="iconWrapper">
<ul class="color">
<li>
<a href="#" title="Select"><span class="color1"></span></a>
</li>
<li>
<a href="#" title="Select"><span class="color2"></span></a>
</li>
<li>
<a href="#" title="Select"><span class="color3"></span></a>
</li>
<li>
<a href="#" title="Select"><span class="color4"></span></a>
</li>
</ul>
</div>
<div id="div1" style="width:17%; height:28%;" ><img src="img/107.png" />
<form method="post" action="step3.php">
<input name="color" type="text" value="" id="hiddencolor" />
<input name="submit" type="submit" value="Submit" />
</form>
</div>