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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:47:43+00:00 2026-06-15T04:47:43+00:00

I have a programming challenge, and I’m wondering what the most bug-free way to

  • 0

I have a programming challenge, and I’m wondering what the most bug-free way to approach it is.

Basically, I have the following HMTL:

<p id="first">
    Hello lorem ispum 
    <a id="link" href="...">Link</a> 
    linkety link blag
</p>

(the id’s are for proof of concept in getting by getElementById: in reality, I get the DOM references element-by-element parsing the page).

The “Hello lorem ispum” and “linkety link blag” text fragments are orphaned — I cannot directly access them. I can only access the whole thing with the paragraph tag, or the inside “a” tag.

What I would like is an array of elements of the stuff in the paragraph.
If they need to get wrapping tags or something in order to get a reference to modify with JavaScript, that’s OK.
E.G., end result:

para[0] = <span>Hello lorem ispum</span>
para[1] = <a id="link" href="...">Link</a>
para[2] = <span>linkety link blag</span>

DOM Objects that I can change/access linking to what’s on the page (NOT strings).

Would it just be a bunch of parsing the paragraph tag’s innerHTML?

This is all for an open source Chrome plugin for disabilities in reading text by simply using up and down arrow keys. If you have any better ideas of how to approach this problem, please let me know!

  • 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-06-15T04:47:44+00:00Added an answer on June 15, 2026 at 4:47 am

    You can iterate over the childNodes

       var para = document.getElementById('first');
    
    var arr = [];
    
    for (var i = 0; i < para.childNodes.length; i++) {
        var elem = para.childNodes[i];
        if (elem.nodeType === 3) {
            var newElem = document.createElement('span');
            newElem.className = 'a';
            newElem.innerHTML = trim(elem.nodeValue);
            elem.parentNode.insertBefore(newElem, elem.nextSibling);
            para.removeChild(elem);
            arr.push(newElem);
        }
        else {
            arr.push(elem)
        }
    
    }
    console.log(arr);
    
    function trim(str) {
        return str.replace(/^\s+|\s+$/g, "");
    }​
    

    Check Fiddle

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

Sidebar

Related Questions

I have been programming in Java (my first language) for about six months and
I have a little programming challenge. In my app I'm using repeating UILocalNotification s.
I have been doing programming, but now I'm facing a challenge. I'm on a
I have been learning the Factor and J languages to experiment with point-free programming.
I have started programming a few weeks ago in java/android. I want to write
I have been programming in .NET for four years (mostly C#) and I use
I have been programming since 1999 for work and fun. I want to learn
I have been programming 10 years, mostly in vba and vb.net but I know
I have a programming experience with statically typed languages. Now writing code in Python
i have been programming for sometime but all of my programming books have not

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.