Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 88169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:31:03+00:00 2026-05-10T22:31:03+00:00

I’ve created two functions to load expanded views of a month in the archive

  • 0

I’ve created two functions to load expanded views of a month in the archive section of my blog when it’s link is clicked:

// Load open view of a month in the Archive section function loadMonth(date) {   // Remove other open month      removeMonth();    // Hide opening month's link   // Define variable to hold month anchor tag      var monthLink = document.getElementById(date);       monthLink.style.display = 'none'; // Hide month anchor    // Define new open month node and its attributes      var openMonth = document.createElement('div');      openMonth.setAttribute('id', 'openMonth');      openMonth.innerHTML = 'Testing one, two, three.';    // Insert open month   // Define a variable to hold the archive Div node      var archive = document.getElementById('archive');   // Insert the open month in the archive node before it's link      archive.insertBefore(openMonth,monthLink);       return;   }   // Close full view of a month and replace with respective link function removeMonth() {    // Define global function vars      var archive = document.getElementById('archive'); // Define a var to hold the archive Div node      var openMonth = document.getElementById('openMonth'); // Define var to hold the open month Div node    // Get date of full view month for replacement anchor tag where ID = date      var month = openMonth.getElementsByTagName('span')[0].innerHTML; // Define var to hold the name of the open month      var date = (new Date(month + ' 15, 2008').getMonth() + 1); // Define var to hold the numerical equivalent of the month      var year = archive.getElementsByTagName('h3')[0].innerHTML.split(' '); // Define var to hold the year being displayed in the archive      date = year[1] + '' + date; // Change date var to string and insert year    // Remove the open month      archive.removeChild(openMonth);    // Show Link for that month      document.getElementById(date).className = 'big'; // Fixes display error when anchor has class firstLink      document.getElementById(date).style.display = 'inline'; // Returns link from display 'none' state      return; } 

The functions work when run on the original static content, but when a second link is clicked in the archive, they do nothing. I am wondering if maybe because the elements that were created by my functions cannot be called by document.getElementById. Perhaps a different method of accessing those nodes should be used, or maybe replacing ‘document’ with something that works on javascript created elements too?

Any advice would be greatly appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:31:03+00:00Added an answer on May 10, 2026 at 10:31 pm

    To answer your main question: document.getElementById does work with dynamically added elements.

    In your sample code you are creating the openMonth div and setting its innerHTML. Then in the remove tag you are doing this:

    var month = openMonth.getElementsByTagName('span')[0].innerHTML; 

    openMonth.getElementsByTagName('span') will not exist and will get an error because there are no span elements. I don’t know if this is a mistake in the code or if it is just a incomplete sample in the post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.