Ander Juaristi
Ander Juaristi

Reputation: 328

How can I change a CSS parameter that comes from a 'class' property?

I'm trying to modify some CSS properties in a given element, this way:

var rsc_menu = document.getElementById("rsc_menu");
rsc_menu.style.top = 303;
rsc_menu.style.height = 29;

Unfortunately, after code execution the element still stays in its original position and preserves its original size. I've noticed that alert(rsc_menu.style.top) and alert(rsc_menu.style.height) both show an empty box.
The element is declared like this:

<div class="resources_menu" id="rsc_menu">

As you can see, it takes all of its styling parameters from a foreign stylesheet; I defined no style tags for it. May that be the problem? Is there any way to accomplish the task without having to change the <div> tag?

Upvotes: 1

Views: 189

Answers (1)

poitroae
poitroae

Reputation: 21367

You have to pass it:

  1. As a string
  2. With a valid unit

So your code would be looking like this:

var rsc_menu = document.getElementById("rsc_menu");
rsc_menu.style.top = "303px";
rsc_menu.style.height = "29px";

Upvotes: 3

Related Questions