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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:45:24+00:00 2026-05-15T21:45:24+00:00

A simple tool to store and display texts longer than a few lines. The

  • 0
A simple tool to store and display texts longer than a few lines.
The search button<div id="xyz">will highlight all</div> the words matching the name of objects that are members of the classes listed in searchedClasses, 
itself a member of the KeySet class. The highlighted words are hypertext.

I want to retrieve characters which are surrounded by div-xyz tag.

example output.
….search button will highlight all the words…..

I am able to get the current div tag text by following.

function myDivHTML(valueName){
     if((obj = document.getElementById(valueName)) && obj != null){
        return obj.innerHTML;
     }      
}

I tried with offsetParent property of element – but there are many possibilities like div tag may be inside bold tag & bold tag may be inside p tag & so on.

what should I do to get surrounding text ? limit may be 10, 20 chars.

Edit :

Surrounding text means -> text left side 10 or 20 chars and right side 10 or 20 chars.

  • 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-15T21:45:24+00:00Added an answer on May 15, 2026 at 9:45 pm

    The easiest way to do this, IMO is wrap the content of the inner div with obscure strings at either side then use a regular expression on the whole paragraph to find the markers you added along with the required number of characters at either side. Something like this:

    var full, result,
        // textContent for w3 compliance, innerText for IE
        txt = "textContent" in document.body ? "textContent" : "innerText",
        // Get references to both divs and store the current text of `xyz`
        out = document.getElementById("outer"),
        xyz = document.getElementById("xyz"),
        old = xyz[txt];
    
    // wrap the inner text with something we can easily search for:
    xyz[txt] = "||||" + xyz[txt] + "||||";
    
    // Get the whole text, change the DOM text back to what it was
    full = out[txt];
    xyz[txt] = old;
    
    // Find the text with our markers and surrounding text:
    result = /.{0,10}\|{4}.*?\|{4}.{0,10}/.exec(full);
    
    alert(result[0]);
    // -> "ch button ||||will highlight all|||| the words"
    
    // Finally, replace your wrapping strings:
    result = result[0].replace(/\|{4}/g, "");
    
    alert(result);
    // -> "ch button will highlight all the words"
    

    You might want to adjust the regex slightly so that it matches, say, two whole words before and after the inner string.

    Example
    http://www.jsfiddle.net/Sy4rT/

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

Sidebar

Related Questions

Sample HTML Data <body style=width:300px;> <h3>Long-Text</h3> A simple tool to store and display texts
I just want a simple tool that will help me quickly write scripts/packages that
I'm making a simple tool that will get a string of MySQL commands and
I wrote a simple tool to generate a DBUnit XML dataset using queries that
I'm looking for a very simple tool to monitor the bandwidth of all my
I'm working on a simple tool that transfers files to a hard-coded location with
Is there a simple Model Checker tool. I am planning to implement a model
Background I am writing and using a very simple CGI-based (Perl) content management tool
I'm making a simple tool to cache function results It look like: global $function_results;
I am trying to make a simple tool tip function (I'm trying to learn

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.