bunu neden javascript ile yapmaya çalışıyorsunuz ki?
css ile daha kolay yapabilirsiniz. hâlâ çözemediyseniz yazabilirim kodu.