I have a scenario where the content of a div is dynamically changed based on checkbox values. For most options, the div displays simple text, but for one specific option, it should display another div (referred to as childDiv).
To achieve this functionality, I am toggling the visibility of the childDiv using jQuery's css()
method. When any of the regular options are clicked, I hide the childDiv by setting its CSS property to display: none
. Conversely, when the exception option is selected, I show the childDiv by changing its CSS to display: block
.
The issue I'm facing is that although the childDiv hides correctly when switching between checkbox options, it fails to reappear when I want it to be visible again.
You can view the demo in this fiddle: http://jsfiddle.net/sandeepy02/jLgyp/
Here is the relevant code snippet:
<div class="switch switch-three candy blue" id="reachout">
<input name="reachout" type="radio" id="tab-41" value="1" checked="checked"/>
<label for="tab-41">Experience</label>
<input name="reachout" type="radio" id="tab-42" value="2"/>
<label for="tab-42">Contact Us</label>
<input name="reachout" type="radio" id="tab-43" value="3"/>
<label for="tab-43">Why?</label>
<div id="test1234">
<div id="test12345">
Option Start
</div>
</div>
<span class="slide-button"></span>
</div>
And the accompanying JavaScript:
jQuery("input[name='reachout']", jQuery('#reachout')).change(function(e) {
if(jQuery(this).val()=="1") {
jQuery("#test1234").html("");
jQuery("#test12345").css("display","block");
}
if(jQuery(this).val()=="2") {
jQuery("#test1234").html("Option 2");
jQuery("#test12345").css("display","none");
}
if(jQuery(this).val()=="3") {
jQuery("#test1234").html("Option 3");
jQuery("#test12345").css("display","none");
}
});
In an attempt to resolve the issue, I also experimented with adding the following styles to the childDiv after setting its display to block:
jQuery("#test12345").css('position', 'absolute');
jQuery("#test12345").css('z-index', 3000);
However, this did not yield the desired outcome. Any insights or suggestions would be greatly appreciated.
Thank you.