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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:47:31+00:00 2026-06-11T00:47:31+00:00

I need to insert customer created content from an input textarea using $.html() of

  • 0

I need to insert customer created content from an input textarea using $.html() of jquery to another div on the page for a live preview feature

But if customer typed javascript inside the content, like:

<script type='text/javascript'>
alert('abc');
</script>

When calling this with .html(), the javascript will get executed, and if I use .text(), then the content will not be regarded as html.

How could I fix this? I created a jsfiddle for it: http://jsfiddle.net/larryzhao/VL82f/

Update:
Maybe I need to made it more clear, I am doing a preview for markdown. So user enters markdown on the textarea, and I converted to html, and display it to the div#dest. What if the user enters script as displayed above? Is there any way to keep the original type but not execute it? If there’s not, then I think I would just write a regexp to wipe the script block out I think..

I found two online markdown tool:
http://daringfireball.net/projects/markdown/dingus this one executes it
http://www.ctrlshift.net/project/markdowneditor/ and this one just wipe the script block out

  • 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-06-11T00:47:33+00:00Added an answer on June 11, 2026 at 12:47 am

    Why not locate a <script>...</script> and escape the characters in the section of the code?

    For example:

    <script src="test/javascript>
    var userInput=document.getElementByID("#input");
    ..
    ..
    ..
    </script>
    
    
    &lt;script src=&quot;test/javascript&gt;
    var userInput=document.getElementByID(&quot;#input&quot;);
    ..
    ..
    ..
    &lt;/script&gt;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to insert selected text on the page into textarea. There must be some
I need to insert Chinese characters inside Oracle Data base using Java (hibernate 3.0
I need to insert an entity in a Azure Table directly from Javascript in
I need to insert a tab into a textarea when a tab is clicked
I need to insert records into a new table from an existing table. I
I need to insert an HTML string into the <head> tag of the current
I need to insert about 1.8 million rows from a CSV file into a
There is a need from a customer to log every data change to a
I need to make an insert statement from a select statement, it looks like
I need to insert new records into an Access database. I'm using Visual Studio

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.