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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:26:35+00:00 2026-06-06T12:26:35+00:00

I am building an javascript application for which I need to know the html

  • 0

I am building an javascript application for which I need to know the html tags that belong to an user selection and then for easy use put them in an array.

I used htmlText which gave me a string that looks something like this:

<h1><span style="color: rgb(102, 51, 153); font-weight: bold; text-decoration: underline;"><sub>test</sub></span></h1>

Since I have hardly any knowledge of regular expressions and what I know just doesn’t seem to do what I want, I was hoping one of you guys could help me on this part.

So what is the best way to make the above string look like the following array?

<h1>,
<span style="color: rgb(102, 51, 153); font-weight: bold; text-decoration: underline;">,
<sub>

My code so far (Don’t know if I am on the right track though):

var fullhtml = SEOM_common.range.htmlText;//Get user selection + Surrounding html tags
var tags = fullhtml.split(SEOM_common.selected_value);//Split by user selection
var tags_arr = tags[0].match(/<(.+)>/);//Create array of tags

Thanks guys for the answers and comments. I managed to build the following method, which does exactly what I want.

find_all_parents : function(selectRange,endNode){
   var nodes = [];
    var nodes_to_go = [];
    if(selectRange.commonAncestorContainer) nodes_to_go.push(selectRange.commonAncestorContainer.parentNode);//all browsers
        else nodes_to_go.push(selectRange.parentElement());//IE<9 browsers

        var node;

        while( (node=nodes_to_go.pop()) && node.tagName.toLowerCase() != endNode){
            if(node.nodeType === 1){ //only element nodes (tags)
                nodes.push(node);
            }

            nodes_to_go.push(node.parentNode);          
        }
        return nodes;
    }
  • 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-06T12:26:36+00:00Added an answer on June 6, 2026 at 12:26 pm

    Don’t use regex for this. Use document manipulation methods instead and fetch the tags themselves (instead of the textual representation of the tags).

    For example:

    var find_all_nodes = function(rootNode){
        var nodes = [];
        var nodes_to_go = [rootNode];
        var node;
        while( (node=nodes_to_go.pop()) ){
            if(node.nodeType === 1){ //only element nodes (tags)
                nodes.push(nodes_to_go);
            }
            var cs = node.childNodes;
            for(var i=0; i<cs.length; i++){
                nodes_to_go.push(cs[i]);
            }
        }
        return nodes;
    }
    

    Once you have a tag you can get all sorts of information from it. I recomend checking out the DOM docs from MDN and the compatibility notes from Quirksmode

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

Sidebar

Related Questions

I am tasked with building an HTML/JavaScript application which is not networked (it runs
I'm building an Android mobile application using HTML, CSS and JavaScript (jQuery) which will
I need to include a dashboard in a JavaScript application I am building. The
I'm building an application for iPhone(iOS 5) using Phonegap(Html + Javascript + Css), and
I'm building a web-based productivity application that has to deal with modest user concurrency,
I'm building an application which subscribes to a Javascript event, and sends out a
I've got an open source static JavaScript + HTML application that's deployed in about
I am building a web application that uses a lot of Javascript. Now I
I'm building a javascript application using object oriented techniques and I'm running into a
I'm building a web-application in JavaScript using the dojo framework. I want to create

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.