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 3278538
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:29:32+00:00 2026-05-17T19:29:32+00:00

I would like to modify text in a document that is in the form

  • 0

I would like to modify text in a document that is in the form of a date and replace it with a link to add an event on that date to Google Calendar. I mostly have this working with one caveat, it tries to add the link inside of already existing links that have dates in them.

document.body.innerHTML = document.body.innerHTML.replace(arrayDates[i], arrayDates[i] + " <a href=\"http://www.google.com/calendar/event?action=TEMPLATE&text=someevent&dates=" + dateString + "&details=&location=&trp=false&sprop=&sprop= target=\"_blank\"> <img src=\"" + chrome.extension.getURL("Config-date-16.png") + "\" title=\"Add this event to your Google Calendar\"> </a> ");

I thought of just running the replacement on the innerHTML string of all p tag elements: eg

arrayP = document.body.getElementsByTagName("p");
for(i=0;i<arrayP.length:i++) {
    arrayP[i].innerHTML = arrayP[i].innerHTML.replace(arrayDates[i], arrayDates[i] + " <a href=\"http://www.google.com/calendar/event?action=TEMPLATE&text=someevent&dates=" + dateString + "&details=&location=&trp=false&sprop=&sprop= target=\"_blank\"> <img src=\"" + chrome.extension.getURL("Config-date-16.png") + "\" title=\"Add this event to your Google Calendar\"> </a> ");
}

but this also includes the children (eg links a tag). I’m not sure of how I can only replace the innerHTML for the p tag elements without it’s children.

Other than removing all elements with an a tag (it will also mangle images and such so I should do the same with those elements as well), running the replacement, and reinserting tag elements, I cannot think of another way around the issue of mangling already existing links (ideas welcome).

Sadly I’m also having trouble with this. I could use a regex to match all elements in the innerHTML string, but I think it would be less kludgey to use the DOM.

I tried the following, but I’m not sure how to get around the problem of not knowing which child tobeReplacedNodes[i] belongs to: (edit: i could probably call .parent or somesuch to figure out what it’s parent is… I’ll try this out again and report back how it goes)

tobeReplacedNodes = document.body.getElementsByTagName("a");
for(i=0;i<tobeReplacedNodes.length;i++) {
    tobeReplacedNodes[i] = document.body.replaceChild(element, tobeReplacedNodes[i]);
}

What I have so far is here: http://code.google.com/p/calendar-event-adder/ (testing branch is most current)

Any ideas/suggestions are 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. Editorial Team
    Editorial Team
    2026-05-17T19:29:33+00:00Added an answer on May 17, 2026 at 7:29 pm

    Walk the DOM recursively, skip over links (and their children) and process only nodes which nodeType is "text". You should have a Text node inside everything that has text, including <p>.

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

Sidebar

Related Questions

I would like to modify a Spotlight metadata attribute of a file within my
I would like to modify the string in a .h file with NAnt before
I have a String which I would like to modify in some way. For
I would like to know how to modify the below code to strip =20
I would like to use a language that I am familiar with - Java,
I would like modify HTML like I am <b>Sadi, novice</b> programmer. to I am
I have this function that works, but I would like to make this one
I would like to have a GtkTextView in my (Python) program which shows text
(please excuse that I didn't use aliases). I would like my query output to
Would like to get a list of advantages and disadvantages of using Stored Procedures.

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.