mike
mike

Reputation: 749

checking css media queries with jquery not working

I cant help but feel stupid. I have a simple setup which should be working but is not. Obviously im missing something simple. Im trying to get it to load on doc ready rather than using window scroll btw.

why does this not work?

if ($(".container").css("width") == "100%"){
    alert("adfgf adg df afdgadg");
}

http://jsfiddle.net/bxLLH/2/

thanks in advance.

Upvotes: 0

Views: 37

Answers (2)

meni181818
meni181818

Reputation: 1101

use width():

if ($(".container").width() == $(window).width()){
    alert("adfgf adg df afdgadg");
}

demo: http://jsfiddle.net/bxLLH/3/

Upvotes: 1

jontewks
jontewks

Reputation: 458

jQuery seems to only return pixel widths rather than percentages. Try using

if ($('.container').width() === $('.container').parent().width())

That will check to be sure something is the same width as it's direct parent element.

Upvotes: 1

Related Questions