0

I want to set the width of a div to the same value as the window height.

I tried something like this:

<script type="text/javascript"> $(".rt-container").style.width = $(window).height(); </script> 

But it's not working. Maybe because I'm an absolute beginner with javascript.

How can I achieve it (by using jquery)?

1
  • 2
    Learn how to debug javascript using your console, jQuery object has no property style, DOM node has Commented Jun 5, 2014 at 17:18

1 Answer 1

2

You can change css styles like this, use the method .css() with option and value as parameters and add the "px" to value, as mentioned in comments:

<script type="text/javascript"> $(".rt-container").css("width",$(window).height() +"px"); </script> 
Sign up to request clarification or add additional context in comments.

3 Comments

px is optional here, anyway +1
@A.Wolff is that because it defaults to px?
@SamCreamer Passing number to css method, jQuery convert it to string for some specific properties: // If a number was passed in, add 'px' to the (except for certain CSS properties) if ( type === "number" && !jQuery.cssNumber[ origName ] ) { value += "px"; } These are excluded properties: "columnCount": true, "fillOpacity": true, "fontWeight": true, "lineHeight": true, "opacity": true, "order": true, "orphans": true, "widows": true, "zIndex": true, "zoom": true

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.