I attempted to create a button that toggles the visibility of a div element.
Initially, I added the "onclick" event to the button and wrote this function:
function showElement() {
var element = document.querySelector('.blocks-fnd-div');
if (element.style.visibility == 'hidden') {
element.style.visibility = 'visible';
}
else {
element.style.visibility = 'hidden';
}
}
However, it only functions properly after the 2nd click. I then tried using just JavaScript and came up with this code:
$('.appr-btn').click(function() {
var element = document.querySelector('.blocks-fnd-div');
if (element.style.visibility == 'hidden') {
element.style.visibility = 'visible';
}
else {
element.style.visibility = 'hidden';
}
})
Since I am not very familiar with this approach, it doesn't seem to work. I would greatly appreciate any assistance you could provide!