make link active on page load

I recently received help here with using java script to handle different link states as well as replacing content in a targeted div id.

My current problem is upon initial page load none of the links are active therefore if a user clicks any link other then the top link (associated with the primary div content) the new content is rendered outside the targeted div. This of course screws up the whole page layout. (see attached image)

Question: How can I set the <id=container1> link to be active upon page load?  
Or is there a better way to fix this problem

The attached code is what I am using within my site.
<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="generator" content="CoffeeCup HTML Editor (">
    <meta name="created" content="Wed, 09 Feb 2011 02:03:23 GMT">
    <meta name="description" content="">
    <meta name="keywords" content="">
   body { background-color: #FFFFFF }

/* navigation */
#navigation {width: 102px; height:129; margin: 0 auto; }

ul#navigation { list-style: none; }
              ul#navigation li {display: block;} 
                     ul#navigation li a { 
                            text-indent: -9999px;
                            display: block;
                            width: 102px;
                            height: 129px;
                            align: left;
                            /*float: left; */
ul#navigation li a.home {
              width: 102px;
ul#navigation li a.about {
              width: 102px;
ul#navigation li {
              width: 102px;
ul#navigation li a.home:hover, 
ul#navigation li a.about:hover, 
ul#navigation li 
    background-position: center right;
.normal { background: url("phoneicon.png") no-repeat scroll center left; }
.clicked { background: url("phoneicon.png") no-repeat scroll center right;}

.content {
  margin-top: 20px; 
    <title>button test 2</title>
<script type="text/javascript"><!--
var saveLink = null;
var saveContainer = null;	
function ReplaceContentInContainer(link) {
  var container = document.getElementById('_')[0]); // passing the id, split on _link
  if (saveLink) saveLink.className=saveLink.className.replace(/ clicked/," normal");
  if (saveContainer)'none';  
  link.className = link.className.replace(/ normal/," clicked");''; // shows the container
  saveContainer = container;
  link.blur(); // remove the border
  return false
<body id="page1">
<br /> 
<div class="content" id="container1">
	Original text for <b>Home</b>
<div class="content" id="container2" style="display:none">
	Original text for <b>about</b>
<div class="content" id="container3" style="display:none">
	Original text for <b>contact</b>
<ul id=navigation>
	<li><a class="home normal" href="#" onClick="return ReplaceContentInContainer(this)" title"home" id="container1_link"></a></li>
	<li><a class="about normal" href="#" onClick="return ReplaceContentInContainer(this)" title"about" id="container2_link"></a></li>
	<li><a class="contact normal" href="#" onClick="return ReplaceContentInContainer(this)" title"contact" id="container3_link"></a></li>
	<!-- end of ul id=navigation --></ul>

Open in new window

image of problem with explainations
Who is Participating?
ProculopsisConnect With a Mentor Commented:

// Untested but try something like this:

window.onload = function() {
  var fake = document.getElementById( "container1_link" );
  ReplaceContentInContainer( fake );
johnm07Author Commented:
I've added your code at the end of the current JavaScript. The result is upon page load the primary link is now active. All other button link selections fill the targeted div as they should.

Great work , thank you for the code and fast response.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.