MoonPoint Support Logo


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

Advanced Search
Sun Mon Tue Wed Thu Fri Sat
23 24 25
26 27 28 29 30 31  
Jul Aug Sep
Oct Nov Dec

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;}

[ More Info ]

[/languages/javascript] permanent link

Tue, Sep 13, 2016 11:19 pm

Check screen resolution and window size with JavaScript

A simple way to check the screen resolution of a visitor to a website is by the following JavaScript:

<script type="text/javascript">

The results of the above code would be as shown below. The numbers represent the resolution in pixels.

Or if you prefer the values to be displayed on separate lines you could use the code below:

<script type="text/javascript">
document.write('Width: '+screen.width+'<br>'+'Height: '+screen.height);

[ More Info ]

[/languages/javascript] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo