0

I am trying to create a form of radioboxes where you can select them simply by mousing over without any clicking. I can't figure out how to do this, my current code doesn't work. Any ideas why? Thanks!

 <script>
    $(document).ready(function () {
            $('.my_checkboxes').mouseover(function () {
                $(this).find('boxclass').click();

            });
</script>
Mathew Pregasen
  • 51
  • 1
  • 2
  • 5

2 Answers2

1

Based on the logic explained in this answer, you would have to use the following:

$(document).ready(function () {
    $('.my_checkboxes').mouseover(function () {
        $(this).find('boxclass')[0].click();
    });
});

DOM Elements have a native .click() method. You need to access the element rather than the jQuery object in order to trigger a programmatic click event.

Community
  • 1
  • 1
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
0

Try this

$(document).ready(function() {
  $(".cb").mouseover(function(){
    $(this).prop("checked", "checked");
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="radio" class="cb" name="test">
<input type="radio" class="cb" name="test">
Joey Chong
  • 1,470
  • 15
  • 20