0

I have the following code that works fine

$(window).load(function(){
$(document).ready(function(){
$("input[name ='_sft_product_cat[]']").parent().next(".children").css("background", "yellow");
})
});

What I am trying to do is turn this into a click event but I cant get it work, I have tried the following

$(window).load(function(){
$(document).ready(function(){
$("input[name = '_sft_product_cat[]']").click(function(){
 $(this).parent().next(".children").css("background", "blue");
return false;
});

What am I doing wrong?

Thanks

Jonas
  • 121,568
  • 97
  • 310
  • 388
Jon Jones
  • 3
  • 3
  • Remember, the $(document).ready is the first node that is load in a page, because the document is literaly the file html, js or php where your code are in. So, it doesn't make a sense put it into the $(window).load http://stackoverflow.com/questions/5182016/what-is-the-difference-between-window-load-and-document-ready – Ramon Schmidt Nov 30 '16 at 04:12

2 Answers2

0

What you miss is closing brackets for the document.ready and window.load functions. Also you need not use window.load and document.ready both , only document.ready is sufficient

$(document).ready(function(){
$("input[name = '_sft_product_cat[]']").click(function(){
 $(this).parent().next(".children").css("background", "blue");
return false;
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <input type="checkbox" name="_sft_product_cat[]"/>
</div>
<div class="children">Hello</div>
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
0

Simply you missed closing brackets. Please use any IDE; like PhpStorm/WebStorm for developing. These IDEs can find this kind of error easily.

Jaber
  • 277
  • 2
  • 10
  • 30