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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:11:16+00:00 2026-05-27T14:11:16+00:00

I don’t think this question has been posed before, at least not in the

  • 0

I don’t think this question has been posed before, at least not in the way I need it answered. I’m using jQuery’s .load function. I have a problem when loading just page fragments.

When using something like:

$('#content').load('loadTest.html');

All of the scripts on loadTest.html load just fine. However, when loading page fragments like this:

$('#content').load('loadTest.html #content');

the scripts are stripped out prior to the DOM being updated

This is clearly documented in http://api.jquery.com/load/ which says:

Note: When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is however called with a selector expression appended to the URL, the scripts are stripped out prior to the DOM being updated, which is why they are never executed. An example of both cases can be seen below:

I understand that I could just externally load the script which can be used anywhere, but the thing is, I’m using a page-wide ajax system where everything is loaded dynamically. So I don’t really feel like having every single javascript function that I’ll ever write (100’s at this point) in external files. Especially because some of these javascript functions are made from values loaded from a database which I can’t account for in a .js file.

Is there any workaround for the scripts being stripped out prior to the DOM being updated? Could I in some way manually load them in? Any tiny example would be helpful to me.

  • 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-27T14:11:17+00:00Added an answer on May 27, 2026 at 2:11 pm

    Like you said. jQuery extracts that element before executing only that block.

    You could modify the output to have the server return the data in a format you need, or just write your own. It would extract the elements you need them output them to the DOM.

    Untested, but it would be along the lines of this..

    $('#content').load('loadTest.html #content,script');
    

    From memory this more valid..

    $.get('loadTest.html',function(r){
        var els = $(r).find('#content,script');
        $('#content').html(els);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this has been asked before, so point me to another question
Don't know if this has been answered before. Have custom routes to users. If
I don't know if this has been asked before, but what i'd like to
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't know if this question is trivial or not. But after a couple
Don't want to sort the entries. using this does not preserve the order as
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know why this is happening, but after submitting a form via JS (using
Don't worry, I'm not going to ask that question, yet again... I am wanting
I don't know why this double json response are not successful: [{first_content:content,...}][{second_content:content,...}] So i

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.