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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:48:40+00:00 2026-06-13T13:48:40+00:00

var text='<div id=main><div class=replace>&lt; **My Text** &gt;</div><div>Test</div></div>’ I want to replace div with class=replace

  • 0
var text='<div id="main"><div class="replace">&lt; **My Text** &gt;</div><div>Test</div></div>'

I want to replace div with class=”replace” and html entities &lt; &gt; comes inside that div with some other text.

I.e the output :

'<div id="main"> Hello **My Text** Hello <div>Test</div> </div>'

I’ve tried

var div = new RegExp('<[//]{0,1}(div|DIV)[^><]*>', 'g');
text = text.replace(div, "Hello");

but this will replace all div.

Any help gratefully received!

  • 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-13T13:48:42+00:00Added an answer on June 13, 2026 at 1:48 pm

    If a Jquery solution is acceptable:

    text = $(text) // Convert HTML string to Jquery object
             .wrap("<div />") // Wrap in a container element to make...
             .parent()        // the whole element searchable
             .find("div.replace") // Find <div class="replace" />
               .each(function()   // Iterate over each div.replace
               {
                 $(this)
                   .replaceWith($(this).html() // Replace div with content
                    .replace("&lt;", "<sometext>")
                    .replace("&gt;", "</sometext>")); // Replace text
               })
             .end().html(); // return html of $(text)
    

    This sets text to:

    <div id="main"><sometext> My Text </sometext><div>Test</div></div>
    

    And to replace it back again:

    text = text.replace('<sometext>', '<div class="replace">&lt;')
               .replace('</sometext>', '&gt;</div>');
    

    http://api.jquery.com/jquery/#jQuery2
    http://api.jquery.com/each/
    http://api.jquery.com/find/
    http://api.jquery.com/html/

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

Sidebar

Related Questions

I've an HTML page like following: <html> <body> <div id=emaildiv class=main style=width:150px;height:80px;></div> </body> </html>
i want to grab the text between two tags, which is in main div,
Main code: var clone = div.clone(); clone.attr('id', sabad_kala_id); $('.content').append(clone); $('div#'+sabad_kala_id).replaceWith('<tr id='+sabad_kala_id+'><td width=50><a class=del_kala id='+sabad_kala_id+'><img
$(document).ready(function() { function countChecked() { var n = $(input:checked).length; $(div).text(n + (n <= 1
This is a simplified and explained version of my code: var ptext=parr.find('div.ptext'); //Text Container
I am using replace method of string, var text = this ex is not
I'm working with a web service that will give me values like: var text
html <div class=btn-group data-toggle=buttons-checkbox> <label class=btn for=id_bar> <input type=checkbox name=bar value=1 id=id_bar /> Bar
Consider the following HTML structure for drop-down menu: <ul class=tabMenu> <li><a href=#>Games</a> <div id=sub>
I have a Silverlight application using C#, with 2 main functions that I want

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.