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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:54:07+00:00 2026-05-27T17:54:07+00:00

I have a div on my page defined as follows: <div id=scripts> </div> I

  • 0

I have a div on my page defined as follows:

<div id="scripts">
</div>

I want to dynamically change the contents of the div and load in some scripts using jQuery. I am doing it like this:

$('#scripts').html('<script language="JavaScript">pn = "landing page"; '+
'cms_1 = "content"; '+
'cms_2 = "promotional "; '+
'cms_3 = "campaign"; '+
'cms_s = "blk:us:dc"; '+
'cms_env = "dev"; '+
'cms_country = "USA"; '+
'<\/script>');

This is in the document.Ready function. However, when I view the source after the page is loaded, the div appears empty and I do not see the script tags. I thought that the script wasn’t getting added but when I add alert("done"); to the script. I get the alert which tells me that the code is executed.

Why can’t I see the changes made when I view the source? Is the Source html rendered before the document.ready function?

  • 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-27T17:54:07+00:00Added an answer on May 27, 2026 at 5:54 pm

    The html function from jquery internally uses the innerHTML property of the browser when available. In general, script blocks inserted via innerHTML don’t get executed almost in any browser.

    Try creating a script tag with the content and appending it to the document instead, e.g.

    var script=document.createElement('script');
    script.type='text/javascript';
    script.html(...);
    
    $("#scripts").append(script);
    

    After seeing your motivation in the comment, I have to add : although you can later physically remove a script tag from the site, this won’t have the effect of unloading its content (e.g. functions defined in the script). The only way to achieve that without refreshing the page is to encapsulate the objects defined in it and delete them manually. This is of course only possible if the content of the script was designed upfront in such a way.

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

Sidebar

Related Questions

I have a jQuery dialog defined as follows <div id=emaildialog title=Contact Us> <!-- Html.RenderPartial(ContactUs);
I have a div (sub area of page with scroll bar) that has some
I have one aspx page with some controls. Also i have one DIV which
I have a page on which I'm using JQuery Mobile. I am having difficulty
I have an aspx page defined as follows: <html xmlns=http://www.w3.org/1999/xhtml> <head runat=server> <title></title> <script
I have a div element that is defined on the top of the page
I currently have a page defined which displays some data in rows. At the
I have a div and an iframe on the page the div has z-index:
I have a div in which a page is loaded with the DojoX Layout
If you have several div s on a page, you can use CSS to

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.