Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display image in place of checkbox?

Tags:

html

jquery

css

I want to display green checked image when checkbox is checked and when not checked empty box. I tried to put checkbox in div and set div's background but it is not helping me out. Any idea what to do? Below is the output I want.

Image

like image 402
Dhwani Avatar asked May 03 '13 06:05

Dhwani


1 Answers

Here is an example, done with a little jQuery and CSS: DEMO

$(".checkbox").click(function() {
  $(this).toggleClass('checked')
});
.checkbox {
  width: 23px;
  height: 21px;
  background: transparent url(http://i.stack.imgur.com/S4p2R.png ) no-repeat 0 50%
}

.checked {
  background: transparent url(http://i.stack.imgur.com/S4p2R.png ) no-repeat 80% 50%
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<div class="checkbox">
</div>
like image 64
Anujith Avatar answered Oct 15 '22 08:10

Anujith