0

I would like to know if this is correct to set the bottom css using javascript:

var productElement2 = document.getElementsByTagName("footer");
productElement2.style.bottom=="0"

I ask this because my script does not work :p. Thanks for the feedback :). If this is correct something else might be wrong but I just want to be sure.

5
  • WHAT DO I DO IF 2 ANSWERS ARE CORRECT ON A DIFFERENT PROBLEM???!!! AARRGGHH :p Commented Jul 9, 2011 at 0:50
  • 1
    Accept whoever gave the most complete answer. My answer, for example, only addressed one of your issues (and I was too lazy to edit to include solutions to the other ones.) Commented Jul 9, 2011 at 0:53
  • there are 2 problems and each post adresses one. there is none that is "more complete" (well now there is but not before :p). Difficult decision :p Commented Jul 9, 2011 at 0:56
  • Guffa's thoughtfulness in editing his answer should be rewarded in place of my laziness ;) Commented Jul 9, 2011 at 0:58
  • that's what i've done :). for others looking at the answers :). Commented Jul 9, 2011 at 1:06

5 Answers 5

5

Use the = operator for assignment. The == operator is for comparison.

productElement2.style.bottom = "0";

Note: If the value is a non-zero value, it needs a unit. Example:

productElement2.style.bottom = "10px";

Also, as kinakuta pointed out, the getElementsByTagName returns an array of elements, so you have to get one elements from the array. If you only have one footer, just get the first element:

var productElement2 = document.getElementsByTagName("footer")[0];
Sign up to request clarification or add additional context in comments.

Comments

3

Be sure you select the specific footer in the returned array you want to style:

var productElement2 = document.getElementsByTagName("footer")[0];

1 Comment

thank you for your awesome comment but it just wasn't complete enough for an "accept". :)
2

Just use one equal sign. Two is for comparison.

productElement2.style.bottom = "0";

Comments

0

This is mostly a CSS question. The CSS style bottom: 0 will not work when position is "static" (the default in-layout position). You would have to specify something like this CSS (with position of absolute or fixed):

#footer {
    position: absolute;
    bottom: 0;
}

or this code:

var productElement2 = document.getElementById("footer");
productElement2.style.position = "absolute";
productElement2.style.bottom = "0";

Also, note the single equals sign to set a variable. You had a double equals sign which is a test of equality, not an assignment.

In addition, your getElementsByTagName returns an array, not a single item. If you wanted to get a single item with a CSS id, you would use getElementById as I've shown here. If you wanted to get the first item from the array returned by getElementsByTagName, then you'd have to reference the first item in the array rather than the entire array.

Comments

0

footer should have position:fixed defined. Try this: http://jsfiddle.net/SSkqb/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.