Please take a look at the example I've created below.
When you click the button, the <g> is toggled and the green dot gets displayed or hidden.
Oddly though, the is(':visible') is ALWAYS returning true, even when the visibility is set to hidden.
Why is this happening?
console.log('Jquery running...')
$("button").click( () => {
var prev = $("g").attr('visibility');
if (prev === 'hidden') {
$('g').attr('visibility', 'visible');
} else {
$('g').attr('visibility', 'hidden');
}
console.log('element is visible:', el.is(':visible'));
});
var el = $('g');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>My Example</p>
<svg width="20" height="30">
<g>
<circle cx="10" cy="10" r="10" fill="green"></circle>
</g>
</svg>
<button> Toggle Dot </button>
UPDATE
I also tried setting display to none earlier and it didn't work either