Trying to get dropdown to show/hide div if selected within two tab classes. Have managed to get this to work in first tab thanks to this solution
Here is the HTML:
<div class="tab2">
<select id="target" style="width:150px; margin-left:40px; height:420px">
<option value="content_1">Option 1</option>
<option value="content_2">Option 2</option>
</select>
<div id="content_1" class="inv" style="width:252px; margin-left:-11px; height:300px">
<a class="scopeTextArea-1">Content 1</a>
</div>
<div id="content_2" class="inv" style="width:252px; margin-left:-11px; height:300px">
<a class="scopeTextArea-1">Content 2</a>
</div>
</div>
<div class="tab3">
<select id="target" style="width:150px; margin-left:40px; height:420px">
<option value="content2_1">Content 3</option>
<option value="content2_2">Content 4</option>
</select>
<div id="content2_1" class="inv" style="width:252px; margin-left:-11px; height:300px">
<a class="scopeTextArea-1">Content 3</a>
</div>
<div id="content2_2" class="inv" style="width:252px; margin-left:-11px; height:300px">
<a class="scopeTextArea-1">Content 4</a>
</div>
</div>
and here is the JQuery as per previous answer:
window.onload = function () {
document
.getElementById('target')
.addEventListener('change', function () {
'use strict';
var vis = document.querySelector('.vis'),
target = document.getElementById(this.value);
if (vis !== null) {
vis.className = 'inv';
}
if (target !== null) {
target.className = 'vis';
}
});
// send change event to element to select the first div...
var event = new Event('change');
document.getElementById('target').dispatchEvent(event);
}
Any bright ideas... Sorry if this is straight forward (or not). I'm new to this business and working on a personal project.
Grateful for any help I can get.