Skip to content
Advertisement

Jquery checkbox toggling only on checking unchecking and then checking

I want to show a div on checking a checkbox and hide the div on unchecking the checkbox.This is what I tried.It works only on checking and unchecking and then checking. I am using jquery 3.5.1.

I think there is a problem with this jquery part logic

jquery part

JavaScript

php part which dynamically displays checkbox from a loop

JavaScript

Here is the frame which needs to be toggled

JavaScript

Advertisement

Answer

I am not sure why you have use $("#"+formid+"").click(function() {.. there is no need to use this simply get id of checkbox and toggle div .

Demo code :

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement