homepage Welcome to WebmasterWorld Guest from 54.196.206.80
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
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
DigitalSky




msg:4556164
 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;
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




msg:4556225
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved