user3540527
user3540527

Reputation: 1

Javascript: Set Width of DIV by Window Height

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)?

Upvotes: 0

Views: 87

Answers (1)

G.Mendes
G.Mendes

Reputation: 1201

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>

Upvotes: 2

Related Questions