Checking Element CSS Display with JavaScript
Can you determine if an element's CSS display property is set to "block" or "none" using JavaScript?
Answers:
Using Computed Style for Inherited or Styled Elements:
As mentioned by sdleihssirhc, if the element's display is inherited or defined by a CSS rule, you need to retrieve its computed style:
return window.getComputedStyle(element, null).display;
Using the Style Property for Inline or JavaScript-Set Styles:
Elements have a style property that provides information about their inline styles or styles set using JavaScript:
console.log(document.getElementById('someIDThatExists').style.display);
This will provide you with a string representing the current display value.
The above is the detailed content of How Can I Check an Element\'s CSS `display` Property Value (block or none) with JavaScript?. For more information, please follow other related articles on the PHP Chinese website!