Issue
I have image button and i want to change button's background image it when i pressed button. At first i have green tick logo and when i pressed image button that green tick logo should changed into red tick logo. And if i pressed it again it should change into green tick logo. And again i pressed it , it should change again into red tick logo and repeat like that when i pressed it again. Help me (:
Solution
Try this:
var clicked = 0
$("#button").click(function() {
if (clicked == 0) {
$(this).css("background", "url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQm19_RGu6ZbKhn_uryzGqZLIldxuLIYX-m6A&usqp=CAU) no-repeat");
clicked = 1;
} else {
$(this).css("background", "url(https://lesspestcontrol.com.au/wp-content/uploads/green-tick.png) no-repeat");
clicked = 0;
}
})
.button {
width: 250px;
height: 250px;
background: url(https://lesspestcontrol.com.au/wp-content/uploads/green-tick.png) no-repeat;
cursor: pointer;
border: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<head>
</head>
<body>
<input id="button" type="button" name="button" value="Search" class="button" />
</body>
</html>
NOTE: I have made the button big, so that it can fit in the images.
Answered By - topsoftwarepro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.