Forum Moderators: open

Message Too Old, No Replies

How to specify TWO IDs for getElementByID

         

DigitalSky

7:10 pm on Mar 18, 2013 (gmt 0)

10+ Year Member



I've got some JavaScript code that is in the head of my site. It takes into account one of the div IDs (left-column) and basically makes that column scroll with the page. I want it to do the same thing for the div with the ID of 'right-column' but I'm having a hard time figuring out how to incorporate that into the code. I tried the following...

var el = document.getElementById('left-column','right-column');


But that didn't work. Maybe someone could help?

Below is a copy of the code I'm using on my site...


function reposition(){
var el = document.getElementById('left-column');

var ScrollTop = document.body.scrollTop;
if (ScrollTop == 0)
{
if (window.pageYOffset)
ScrollTop = window.pageYOffset;
else
ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
if(ScrollTop < 185)
el.style.top = 185 - ScrollTop + "px";
else
el.style.top = "15px";
}


Thanks in advance!

lucy24

9:58 pm on Mar 18, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I assume you've discarded the option of feeding the two IDs to the function in alternation. Shouldn't place too much of a strain on the server, and unless your users are on dialup I can't imagine they would see the difference.

Alternately: Would getElementsByName (plural) work? Generally you think of "name" as retro and outdated compared to "id", but this is one situation where the two things simply do different things.