I am pretty new to java-script. So sorry if this is a stupid question.
I have the JavaScript function for some accordion elements, The function it is work without any problem. But I want when I click on any accordion element get the id attribute of that accordion (As you see in click function event), then put this id before the contentTypeValue selector in the second function.
The showHideUniMul function doesn't work, I think this is due to the itemId variable. How can use the itemId outside the click event function until work with showHideUniMul function?
Info the showHideUniMul function work without any problem when I don't use itemId variable and the itemId return to the id attribute successfully.
$('ul#menu-to-edit li a.item-edit').click(function() {
var itemId = $(this).parent().parent().parent().parent().attr('id');
});
var showHideUniMul = function() {
var contentTypeValue = $(itemId + ' .field-content-type input:checked').val();
if (contentTypeValue === 'uniform') {
//some codes here
} else if (contentTypeValue === 'multiple') {
//some codes here
} else {
//some codes here
}
};
showHideUniMul();
contentType.on('change', showHideUniMul);
EDIT
This is my Html structure
<ul id="menu-to-edit">
<li id="1">
<div>
<div>
<span>
<a class="item-edit">Click Me and then check radio boxes</a>
</span>
</div>
</div>
<div>
<p class="field-content-type">
<input type="radio" name="uniform[1]" value="uniform" />
<input type="radio" name="multiple[1]" value="multiple" />
</p>
</div>
</li>
<li id="2">
<div>
<div>
<span>
<a class="item-edit">Click Me and then check radio boxes</a>
</span>
</div>
</div>
<div>
<p class="field-content-type">
<input type="radio" name="uniform[2]" value="uniform" />
<input type="radio" name="multiple[2]" value="multiple" />
</p>
</div>
</li>
</ul>