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

The Archive Base Latest Questions

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

like it’s mentioned in the title i’m willing to replace a string inside a

  • 0

like it’s mentioned in the title i’m willing to replace a string inside a script tag <script>. what i want to replace is the string //WRITE by something else.

<script name="general" id="general" type="text/javascript">
some code
//Write
</script>

So i automatically tried :

ch="new string";
document.getElementById("general").replace('// WRITE',ch);

But i got the following error : Uncaught TypeError: Object #<HTMLScriptElement> has no method ‘replace’.
So i understand that unlike <div>, <script> doesn’t use that method. Is there an equivalent method ? Thanks in advance.

  • 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-12T23:41:07+00:00Added an answer on June 12, 2026 at 11:41 pm

    The object returned by “getElementById” is a DOM Element so you can change its contents by assigning to the innerHTML attribute:

    var general = document.getElementById("general");
    general.innerHTML = general.innerHTML.replace('//WRITE', ch);
    

    Be careful about your replacement token – your sample “script” tag uses the literal string “//Write” whereas your attempted regular expression will look for “// WRITE”, which does not exist. You must use the same literal string if you want this to work.j

    [Edit] Note that scripts as defined per your example are run immediately when the browser loads the page so trying to modify them with another script will likely not have any impact. Moreover, this strategy will not work if you try to modify a script that would occur later in the page because the browser will not have loaded it so there will be no element with the target id. One possibility is to modify a function that is defined so it can be called later but this also might not work. A better strategy for including dynamic content in a JavaScript block is to have the JS itself seek information in the DOM instead of the other way around.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
Like the title says, I just need something to migrate a set of tables
Like a start button on windows ) or something like that, I want to
Like setFont(QFont(Helvetica,16,1)) ,I want to summerize these fonts.However,I dont't know how many fonts there
Like the title says I'm having some trouble printing out symbol codes and their
Like many others Knockout developers before me, I encountered a slow running script warning
Like the title says, I'm wondering if the use of WebClient is the proper
Like in topic. It is possible to do it? Or make something to use
Like i sayed in the title, i need to build an array and change

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.