Simon Suh
Simon Suh

Reputation: 10882

if element width is greater than, then execute jQuery code

I have the following javascript right below the relevant html area and it is not seem to be working. I'm pretty sure I have the correct method of getting the width of the relevant div tag but not sure why the

<script type="text/javascript">
var pageWidthNow = document.getElementById('top-area').clientWidth;

if (pageWidthNow > 700) {
    $('#search-form').addClass(topRightSearchBox);
};
</script>

Upvotes: 1

Views: 3084

Answers (1)

Smern
Smern

Reputation: 19066

it looks like you just need to add quotes

$('#search-form').addClass("topRightSearchBox");

Upvotes: 2

Related Questions