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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:05:46+00:00 2026-05-22T12:05:46+00:00

Does anyone know of a work around for jquery .load() stripping out the script

  • 0

Does anyone know of a work around for jquery .load() stripping out the script tags loaded from external content?

There’s a lot of documentation of the fact that this happens but after something like 4 hours searching the net I can’t find a work around?

I’m loading dynamically generated divs – similar to a page of search results – and need to bind a .click() to an element within each dynamically generated div. I’ve a php file that does the html generation work and returns all the html as a string however I can’t bind the jquery .click() as the script tags containing the jquery function get stripped out.

here’s the code that loads the external content by calling the php file…

$("#titles_wrap").load("m_scripts/m_php/titles_loader.php", function(){
                                                                $..some code
                                                                });

and here’s the loop from the php file that generates the divs (this works fine)…

$tag1='<script type="text/javascript">';
$tag2='</script>';

while($result_array = mysql_fetch_array($result)) {

            if($i2<=($titles_total)){

                $_SESSION['titles_string'] .= '<li id="listItem_'.$i2.'">

                                                <div id="titles_list_item">

                                                    <div id="titles_list_image_box" style="background-image: url(../../images/thumbs_test/'.$result_array[0].'); background-repeat: no-repeat; ">'.($i2+1).'</div>
                                                    <div id="title_php_loader"></div>
                                                        <div id="title_info_wrap">

                                                        <div id="title_current"><span class="title_current_grey" >current title: </span><br>'.$result_array[1].'
                                                            </div>

                                                                <div id="title_form_wrap">
                                                                    <span class="title_current_grey" >new title: </span><br><input name="title_input_'.$i2.'" id="title_input_'.$i2.'" type="text" class="title_input"></input>
                                                                    <div id="title_send" class="title_send_'.$i2.'">GO</div>
                                                                </div>

                                                            </div>


                                                    '.$tag1.'
                                                    $(".title_send_'.$i2.'").click(function(){$("#title_php_loader").load("m_scripts/m_php/title_sender.php")})
                                                    '.$tag2.'

                                                </div>
                                            </li>';
                $i2++;
                                }
            }

Sorry if this second code block is a bit on the ‘overkill’ side – let me know if a simplified excerpt would be more useful. That said, you can see on the 8th from last line of the php code the jquery function that should get written into each div with a dynamically assigned selector.

Of course, it could be that there’s other errors in the code however I’m not going to be able to test it until I can get .load() to stop trashing it!

If anyone’s found a solution to this – or even a workaround of limited grace – brilliant!

Thanks in advance,

Cheers,

Scott

EDIT – EDIT – EDIT – EDIT – EDIT – EDIT – EDIT – EDIT

@T.J. Crowder
@Frug

Thanks for your help!

I’ve just had a good hard look at the pages involved in your demo and yes, I see you’ve got it working. Seems amazing cos there they are – those script tags and there are SO many people out there who can’t get it to work – unfortunately I’m one of them!

The only differences I see between your demo and my code situation was

1) no type declaration in the opening script tag,

2) you’re loading a page with script tags as part of the DOM, whereas I was loading php string output (I really don’t think this matters tho’, eh? By the time it hits the client it all comes to the same thing, no?)

3), your .load call was fetching a whole page whereas mine was returning only elements. I’ve since changed the output string to include all , and tags but grrrrrr…I still can’t get dem damn script tags to show up in the DOM.

Any suggestions? There’s loads I don’t know about so could be anything! thanks S

  • 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-22T12:05:47+00:00Added an answer on May 22, 2026 at 12:05 pm

    jQuery load doesn’t strip out script tags (example), and there are no script tags in the content you’re returning from your PHP script. There is some JavaScript, but it’s not correctly embedded in script tags and so it’s not being recognized by the browser.

    If you want the JavaScript in this:

    ...
    '.$tag1.'
    $(".title_send_'.$i2.'").click(function(){$("#title_php_loader").load("m_scripts/m_php/title_sender.php")})
    '.$tag2.'
    ...
    

    to be recognized as JavaScript, put it in a script tag.

    ...
    '.$tag1.'
    <script>"$(".title_send_'.$i2.'").click(function(){$("#title_php_loader").load("m_scripts/m_php/title_sender.php")})</script>
    '.$tag2.'
    ...
    

    …or better yet, use a single script tag at the end of the content to hook things up, or the callback on the load function.


    Update: Re your edit:

    1) no type declaration in the opening script tag,

    Doesn’t matter, see this updated example. The browser interprets the script tag according to the same rules it always applies.

    2) you’re loading a page with script tags as part of the DOM, whereas I was loading php string output (I really don’t think this matters tho’, eh? By the time it hits the client it all comes to the same thing, no?)

    Right, it all comes to the same thing once it gets to the browser.

    3), your .load call was fetching a whole page whereas mine was returning only elements. I’ve since changed the output string to include all , and tags but grrrrrr…I still can’t get dem damn script tags to show up in the DOM.

    My example is just loading a snippet, not a full page.

    I don’t know why yours isn’t working. I wondered if it related to multiple script elements being output in a loop, or the fact you were hooking up a click handler, but it’s not either of those.

    There’s nothing for it but to take your non-working example and peel layers away bit by bit until you find the part that, when you remove it, lets it start working. Fundamentally, again, it’s not that using load makes the scripts not work (regardless of how many people you find who think that’s the case; it’s a big world, there are lots of people who think nearly anything). You have to let go of the idea that this is related to jQuery’s load function doing anything to the scripts; it probably isn’t.

    The key to debugging this kind of thing really is simplify, simplify, simplify. make sure the HTML being returned by the server for the ajax calls looks the way you think it does (no weird quotes or something). Try to do it with static pages. Etc.

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

Sidebar

Related Questions

Does anyone know why using-declarations don't seem to work for importing type names from
Does anyone know if it is possible to prevent a work item from being
Does anyone know how function indexes work in databases?
Does anyone know how the validation will work with V1? I'm at the crossroads,
Does anyone know how exactly RSLs work with AIR? I have a terminal server
Does anyone know how DbDataReaders actually work. We can use SqlDataReader as an example.
Does anyone know utility which can measure work intensity. For example - keystrokes\mouse clicks
Does anyone know how to get IntelliSense to work reliably when working in C/C++
Does anyone know why typedefs of class names don't work like class names for
Does anyone know if the LIMIT and OFFSET clause work when using the UPDATE

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.