MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
October
Sun Mon Tue Wed Thu Fri Sat
           
3
         
2016
Months
Oct


Mon, Oct 03, 2016 7:49 am

Hiding an element on a webpage with JavaScript

JavaScript can be used to control the display of elements on a web page. E.g., suppose I don't wish visitors to a webpage to see a certain element on the page unless the width of their browser window is a specified value. The element could be a div, which might contain an advertisement or some other image that might be too wide for a browser window that was less than a certain width. So I want to hide the display of the element, so that it doesn't detract from the aesthetics of the page.

I could put the following code in the HEAD section of the webpage, if I wanted any DIV element on the page that has a class of sometimesHide to be hidden in certain circumstances. The styling I chose below is arbitrary, you could use would ever you preferred and you could put the style information in an external Cascading Style Sheets (CSS) file, instead.

<style type="text/css">
   .sometimesHide { background-color: MediumOrchid; color: white; margin: 25px;}
</style>

[ More Info ]

[/languages/javascript] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo