I'm trying to 'show' a div, while hiding other sibling divs using jQuery. Here is my code:
const jq = require('jquery');
function hideAllBut (ShowDivID) {
alert('test');
jq('div.content > div').each( () => {
if (jq(this).attr('id') === ShowDivID) {
alert(jq(this).attr('id'));
jq(this).show();
} else {
alert(jq(this).attr('id'));
jq(this).hide();
}
});
}
The function alerts at test, and alerts 'undefined' twice (as expected) under the 'else' statement. The content that is shown by default is not hidden. So I have two problems - my call to get the 'id' attribute is not working, and the hide() function is not hiding the div. Any ideas what I'm doing wrong?
The html looks like:
<html>
<body>
<div class='content'>
<div id='a'>
</div>
<div id='b' hidden>
</div>
</div
</body>
</hhtml>