function classInfo(e){
document.getElementById('classRight').setAttribute('display','none');
alert(e);
}
I think this code is very straightforward bit it's not working, and is not hiding the element in question. I am getting my alert, which makes me think there is no issue.
Any help would be appreciated.
The default display value for most elements is block or inline . This panel contains a <div> element, which is hidden by default ( display: none ). It is styled with CSS, and we use JavaScript to show it (change it to ( display: block ).
setAttribute() Sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value. To get the current value of an attribute, use getAttribute() ; to remove an attribute, call removeAttribute() .
Answer: Use the jQuery css() Method You can use the jQuery css() method to change the CSS display property value to none or block or any other value. The css() method apply style rules directly to the elements i.e. inline.
The setAttribute() method is used to set or add an attribute to a particular element and provides a value to it. If the attribute already exists, it only set or changes the value of the attribute. So, we can also use the setAttribute() method to update the existing attribute's value.
display
is not an attribute - it's a CSS property. You need to access the style object for this:
document.getElementById('classRight').style.display = 'none';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With