-2

My sourcecode :

 <input class="eanvoera5" type="checkbox" name="nieuwpid">

Gets transformed for design to the below code : (when i view the page in my browser)

   <div class="icheckbox_minimal checked" style="position: relative;" aria-checked="true" aria-disabled="false">
   <input class="eanvoera5" type="checkbox" name="nieuwpid" style="position: absolute; opacity: 0;">
   <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: none repeat scroll 0% 0% rgb(255, 255, 255); border: 0px none; opacity: 0;"></ins>
  </div>

Problem :

I can not get my Jquery functions working for the checkbox. If the checkbox is clicked I want to show / hide another box.

Code Jquery :

$(".eanvoera5").on('click', function() {
alert('hitest');
}

Its driving me crazy.. Somebody has an idea ?

AVGG
  • 21
  • 5

4 Answers4

2

You are missing ); at the end of your function...

$(".eanvoera5").on('click', function() {
    alert('hitest');
}); // <!-- HERE
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input class="eanvoera5" type="checkbox" name="nieuwpid">
Turnip
  • 35,836
  • 15
  • 89
  • 111
  • Thank you I know this works, it was a typo for the example. In normal code it works but my code gets rewritten for design as you can see in my example. – AVGG May 01 '15 at 12:23
  • Some AJAX Is changing this afterwards, I know if i write this code directly in my source its working. But thanks. – AVGG May 01 '15 at 12:28
0

As you can see there is a syntax error as you are missing the ); closing, but What seems to me that DOM is getting changed via some other script operation. As you mentioned, It might be possible that you should delegate the event to the closest static parent or to the document:

And instead of click you should use change because checkboxes have checked prop, which always gets changed when clicked although click also works.

$("body").on('change', ".eanvoera5", function() {
   alert('hitest');
});
Jai
  • 74,255
  • 12
  • 74
  • 103
  • Your answer seems to be the most true. Still not working. Will experiment further, thanks. – AVGG May 01 '15 at 12:28
0

Maybe changing your click function to something like this for jQuery

$(".eanvoera5").click(function() {
    alert('hitest');
});

Take note of the closing ); like everyone above mentioned

https://jsfiddle.net/ToreanJoel/jjd2ode8/

TrojanMorse
  • 642
  • 1
  • 8
  • 16
0
$(".eanvoera5").on('ifChecked', function(event){
alert('hitest');
});

This function works. Documentation can be found here: https://github.com/fronteed/iCheck

iCheck does not work well with Jquery.

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
AVGG
  • 21
  • 5