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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:30:16+00:00 2026-05-28T21:30:16+00:00

I have a DOMstring object, text of some web page which I get from

  • 0

I have a DOMstring object, text of some web page which I get from server using XMLHttpRequest. I need to cut a substring from it, which lies between some specific tags. Is there any easy way to do this? Such methods as substring() or slice() won’t work in my case, because content of the web page is dynamic, so I can’t specify the beginning and the end of substring (I only know that it’s surrounded by <tag> and </tag>).

  • 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-28T21:30:17+00:00Added an answer on May 28, 2026 at 9:30 pm

    A DOMString is just implemented as a string in most (all?) JavaScript browser environments so you can use any parsing technique you like, including regular expressions, DOMParser, and the HTML parser provided by libraries such as jQuery. For example:

    function extractText(domString) {
      var m = (''+domString).match(/<tag>(.*?)<\/tag>/i);
      return (m) ? m[0] : null;
    }
    

    Of course, this is a terrible idea; you should really use a DOM parser, for example, with jQuery:

    $('tag', htmlString).html();
    

    [Edit] To clarify the above jQuery example, it’s the equivalent of doing something like below:

    function extractText2(tagName, htmlString) {
      var div = document.createElement('div'); // Build a DOM element.
      div.innerHTML = htmlString; // Set its contents to the HTML string.
      var el = div.getElementsByTagName(tagName) // Find the target tag.
      return (el.length > 0) ? el[0].textContent : null; // Return its contents.
    }
    extractText2('tag', '<tag>Foo</tag>'); // => "Foo"
    extractText2('x', '<x><y>Bar</y></x>'); // => "Bar"
    extractText2('y', '<x><y>Bar</y></x>'); // => "Bar"
    

    This solution is better than a regex solution since it will handle any HTML syntax nuances on which the regex solution would fail. Of course, it likely needs some cross-browser testing, hence the recommendation to a library like jQuery (or Prototype, ExtJS, etc).

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

Sidebar

Related Questions

I have hundreds of properties that need to be set in an object, which
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Is there a way to get object.__doc__ as a raw string, apart from adding
I have Python classes with object attributes which are only declared as part of
I have some python module, that I import as: from mygraph.draw import pixel The
I have working C++ code using swig which creates a struct, passes it to
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have a n-tire web application and search often times out after 30 secs. How
Have you managed to get Aptana Studio debugging to work? I tried following this,

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.