Welcome to WebmasterWorld Guest from 54.159.90.0

Forum Moderators: open

Message Too Old, No Replies

How to specify TWO IDs for getElementByID

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

Junior Member

5+ Year Member

joined:Mar 19, 2010
posts: 51
votes: 0


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!
9:58 pm on Mar 18, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13674
votes: 439


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members