feeling a bit silly I cant seem to get this working 100%...
Following code works fine when selecting a radio button but I need it to run on page load as well - can't seem to figure out how to get this to play ball. The (many) post on here don't seem to offer the solution - I'm fairly confident I'm missing something very simple!! (as you may have guessed JS is not my forte!!)
$('#cvl_mb_services .content-switch').on('click', 'input[type="radio"]', function(){
var parent = $(this).parent().parent().parent().parent().parent().parent().attr("id");
var inputValue = $(this).closest('input[type="radio"]').attr("value");
var targetBox = '#' + parent + ' .' + inputValue + '-fields';
$(targetBox).removeClass('hide-field');
// console.log(parent + ' ' + inputValue + ' ' + targetBox);
});
Html mark up is as follows. (Things to note: There can be several .box
containers and I don't have much direct control of the html since it's outputted by a plugin)
<div id="cvl_mb_services">
<div id="box_01" class="box">
<div class="content-switch">
<ul>
<li><input type="radio" class="content-option" value="header" checked="checked"><label>Header</label></li>
<li><input type="radio" class="content-option" value="content"><label>Content</label></li>
<li><input type="radio" class="content-option" value="footer"><label>Footer</label></li>
</ul>
</div>
<div class="fields header-fields hide-field">
<p>You should only see this content of the Header Option is selected (or pre-selected) in this box</p>
</div>
<div class="fields content-fields hide-field">
<p>You should only see this content of the Content Option is selected (or pre-selected) in this box</p>
</div>
<div class="fields footer-fields hide-field">
<p>You should only see this content of the Footer Option is selected (or pre-selected) in this box</p>
</div>
</div><!-- #box_01 -->
<div id="box_02" class="box">
<div class="content-switch">
<ul>
<li><input type="radio" class="content-option" value="header"><label>Header</label></li>
<li><input type="radio" class="content-option" value="content" checked="checked"><label>Content</label></li>
<li><input type="radio" class="content-option" value="footer"><label>Footer</label></li>
</ul>
</div>
<div class="fields header-fields hide-field">
<p>You should only see this content of the Header Option is selected (or pre-selected) in this box</p>
</div>
<div class="fields content-fields hide-field">
<p>You should only see this content of the Content Option is selected (or pre-selected) in this box</p>
</div>
<div class="fields footer-fields hide-field">
<p>You should only see this content of the Footer Option is selected (or pre-selected) in this box</p>
</div>
</div><!-- #box_02 -->
</div>
Thanks in advance