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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:17:33+00:00 2026-06-07T12:17:33+00:00

I have a div that contains some html and a lot of Javascript <div

  • 0

I have a div that contains some html and a lot of Javascript

<div id="mydiv">
<p>Hello Philippines</p> my first time in Philippines is nice
<script type="text/javascript">alert("how was it became nice?");</script>
well I experienced a lot of things
<script type="text/javascript">alert("and how about your Japan's trip?");</script>
well its more nicer ^^ but both countries are good! hahah
</div>

I want to put the non-Javascript code and Javascript code in two separate variables:

var html = $("#mydiv").html();

My problem here is that my javascript is executing, which makes me stop to create the code I want which is the storing of javascript and non-javascript to two different variables.

  1. how can I stop the javascript codes from executing when they are
    get inside the div?
  2. how can I store the javascript and non-javascript code into two different variables safely?

NOTE: I need the stored javascript for later execution

  • 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-07T12:17:35+00:00Added an answer on June 7, 2026 at 12:17 pm

    you can use code tag instead of script:

    html:

    <div id="mydiv">
    <p>Hello Philippines</p> my first time in Philippines is nice</p>
    <code>alert("how was it became nice?");</code>
    well i experienced a lot of things
    <code>alert("and how about your Japan's trip?");</code>
    <p>well its more nicer ^^ but both countries are good! hahah
    </p>
    </div>
    

    js:

    var html = $('#mydiv *').not('code').html()
    var code = $('#mydiv code').text()
    

    http://jsfiddle.net/dMDy5/3/

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

Sidebar

Related Questions

I have a div with id=images. The div contains some images that are each
I have a page that contains an iframe that gets loaded using Javascript: index.html
I have 2 div tag. The first contains a table. The second contains some
I have some jQuery that hides half a div that contains an image and
in my aspx page i have a div which contains simple html ,has some
In HTML, I have a div that contains a table of labels and textboxes
I had this idea... let's say I have a DIV that contains some text.
I have an Html that contains something like: (Multiple divs within div A). <div
I have a div that contains a list of messages (it's a chatroom application).
I have a div that contains a ul and in each li there is

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.