I use the following function to expand the footer border for a website I'm creating:

<script type="text/javascript">
var x=5; <!--original height-->
function expand() {

document.getElementById("footer").style.height=x+'em'; <!--Gets the height from css.css in the div "move"-->
if(x>10) { <!--Desired height after expansion-->
clearTimeout(t);
return;
}
x++; <!--desired height isn't yet reached, keep expanding-->
t=setTimeout('expand()',0); <!--Speed of expansion-->
}
</script>

where I get the element by id however I've changed the footer to a div class now so it doesn't read this properly and the border doesn't expand. How can I work around this problem?

Why is it you aren't just incrementing the size? 'setTimeout()' for zero millis?

I'm not too sure^^ Would that be a better option? And how would it be done?

x += 1; // or 2 or 3

I don't understand how that help me get element by class?

I don't understand the connection between the code you showed and the goal you state. Please explain!

You could use document.getElementsByClassName(nameOfClassName) on Firefox. However, I doubt that you want your web page to work only on Firefox. What you can do is to go through each elements by yourself.

function myGetElementsByClassName(tagname, classname) {
  var elems = document.getElementsByTagName(tagname)
  var results = new Array()
  if (elems.length>0 && classname) {
    for (var i=0; i<elems.length; i++) {
      if (elems[i].className==classname) {
        results.push(elems[i])
      }
    }
  }
  return results
}

// Assume that you are looking for all div elements having "footer" as class name
// Then you call it as ...
var myFooters = myGetElementsByClassName("div", "footer")

PS: As others said above, why are you using "setTimeout()" with 0 time??? If you are going to call it, why not simply call the function instead of using "setTimeout()"?

Managed to solve it myself, thanks anyway!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.