0

It seems like the isTablet function returns true at later point. Why, and how do I fix it so isTablet says it is a tablet when the CSS media query does.

function isTablet() {
    return $(window).width() >= 768;
}

and

<link href="css/tablet-default.css" media="all and (min-width: 768px)" rel="stylesheet" type="text/css" />
1
  • Wouldn't you want the device-width in your media query?otherwise changing the window size may toggle you in and out of the display. Commented Mar 20, 2012 at 15:04

2 Answers 2

3

Instead of hard coding the width in the isTablet function (following DRY), you could check for the state of an element that changes due to the media queries.

For example, if you have an element which is normally display: none but has display: block for tablets, have isTablet check the visibly of that element instead.

Sign up to request clarification or add additional context in comments.

Comments

0

The .width() function does not include paddings or margins.

http://api.jquery.com/width/

That may be the difference you are noticing.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.