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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:41:22+00:00 2026-06-12T16:41:22+00:00

The below is in my userscript. It doesnt do the alert because when i

  • 0

The below is in my userscript. It doesnt do the alert because when i replace the html i am clobbering it somehow.

How do i replace regular text in a div or span that is literally domain[dot]com so it will appear as domain.com? Well the below works but breaks code running after and other userscripts.

$(function() {
    var html = $('body').html();
    var res=html.replace(/\[dot\]/g, ".");
    $('body').html(res);
    //doesnt call, however html is replaced
    alert('a'); 
});
  • 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-12T16:41:23+00:00Added an answer on June 12, 2026 at 4:41 pm

    Replace the text in the page instead of replacing in the entire HTML. If you get the entire HTML and put it back, that will make it reparse all the code and put it back as it was when initially loaded, whcih means that any events bound to any elements are gone.

    Use a recursive function to find the text nodes in the document and do the replacing on the text in each node:

    function replaceText(node, replacer) {
      var n = node.childNodes;
      for (var i = 0; i < n.length; i++) {
        if (n[i].nodeType == 3) {
          n[i].nodeValue = replacer(n[i].nodeValue);
        } else {
          replaceText(n[i], replacer);
        }
      }
    }
    
    $(function(){
    
      replaceText(document.body, function(s){
        return s.replace(/\[dot\]/g, '.');
      });
    
    });
    

    Demo: http://jsfiddle.net/Guffa/ex83P/

    As you see, there is no jQuery in the function, because jQuery only deals with elements, there are no methods to deal with text nodes.

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

Sidebar

Related Questions

below is a java script function and the html for the clicked item that
Below is the code that I am writing in HTML and I'm getting what
I'm writing a userscript for a page which has this HTML code block.. <span
Below is code to an inherited ComboBox. The issue is that the ComboBox is
Below am posting my jsp page. home.jsp <%@taglib uri=/WEB-INF/struts-bean.tld prefix=bean%> <%@taglib uri=/WEB-INF/struts-html.tld prefix=html %>
Below, I want div A to act as a two column layout for it's
Below is a VBA function that I created for use in Excel for converting
below is my code that plots a function, and I need to move the
Below is a very simple AJAX request that works just fine until I put
Below is my validation() function which controls some messages in an alert: function validation()

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.