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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:14:17+00:00 2026-05-31T01:14:17+00:00

I have a single page web application using jquery and a set of embedded

  • 0

I have a single page web application using jquery and a set of embedded templates. A template may contain tag like below:

<script type="html/template" id="sample">

<script type="text/javascript" charset="utf-8">alert('x');</script>


</script>

and a jquery code to retrive the template is

$("#sample").html();

The output of above jquery command is

<script type="text/javascript" charset="utf-8">alert('x');

Instead of

<script type="text/javascript" charset="utf-8">alert('x');</script>

How can I fix this output ?

  • 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-31T01:14:19+00:00Added an answer on May 31, 2026 at 1:14 am

    Everything inside a <script> is expected to be script, not HTML.

    The browser sees:

    <script type="html/template" id="sample">

    and starts interpreting everything that subsequently appears as script, when it reaches the inner <script its seen as just being text.

    The exception to this is </script> which the browser is looking for in order to switch contexts from script to HTML, so when it sees the 1st </script> in:

    <script type="text/javascript" charset="utf-8">alert('x');</script>

    It assumes the opening script block is complete & switches back to expecting HTML, correctly setting the content of the outer script node to:

    <script type="text/javascript" charset="utf-8">alert('x');

    You can either implement what your trying to do on the server and parsing there, or use a different approach to templating.

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

Sidebar

Related Questions

I have a struts2 application with a single page that may show one of
Have you experimented with single page web application, i.e. where the browser only 'GETs'
I am creating a web application using EJBs and servlets. I have a page
I'm writing single-page web application. Client interacts with server using AJAX retrieving quite complex
I have a photo gallery web page where a single <img src="XXX" /> element's
Let's say I have a web page that currently accepts a single ID value
I have recently designed a web application that I would like to write in
I have a single-page JavaScript application, held within an ASP.NET MVC 3 website. In
I have a web application which uses LDAP for log in. I'm using Openid4Java
I have created a form in my web application which has only a single

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.