homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

How to specify TWO IDs for getElementByID

5+ Year Member

Msg#: 4556162 posted 7:10 pm on Mar 18, 2013 (gmt 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;
ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
if(ScrollTop < 185)
el.style.top = 185 - ScrollTop + "px";
el.style.top = "15px";

Thanks in advance!



WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4556162 posted 9:58 pm on Mar 18, 2013 (gmt 0)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved