Create div with script tag inside using jquery

I have content that I load dynamically using jquery. The content is HTML with a script tag.

So, I have something like this.

var content = '<script language="javascript" type="text/javascript">alert("test");</script><div>mydiv</div>';

      

I want to create a new div with this content using jquery

var dialog = $('<div class="modal-popup">' + content + '</div>');

      

But there is no script tag in the newly created div (dialog).

This has worked in the past. We've updated jquery from 1.5.1 to 1.7.1. I have already updated jquery with the same result.

We are using ist to create a print dialog and we learned that we can no longer print. I am browsing the repository but cannot find the changes we made.

What is the reason the script -tag is missing?

EDIT: It depends on the JQuery release. It works in version 1.5.1, not in version 7.1.2.

The reason it didn't work in my previous test with v1.5.1 was because the browser was caching jquery for some reason

EDIT 2: In this example, the content is a string variable to keep things simpler. In a real environment, the content is populated with $ .get and is an HTML document with javascript in it.

+3


source to share


1 answer


The end </

tag sequence </script>

will complete the parsing of the script element in HTML.

You should never have characters </

anywhere in your script markup, even if it is part of a string. Browsers running HTML4 should stop script block if visible - Phrogz



Clearing the forward slash <\/

should fix the problem.

0


source







All Articles