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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:13:35+00:00 2026-05-28T03:13:35+00:00

<script src=http://code.jquery.com/jquery-1.7.1.min.js></script> <script> var newvalue = ‘<img class=youtube_replace youtube_canvas data-code=Wn-_MyJV37E src=http://img.youtube.com/vi/Wn-_MyJV37E/0.jpg />’; var abc

  • 0
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
var newvalue = '<img class="youtube_replace youtube_canvas" data-code="Wn-_MyJV37E" src="http://img.youtube.com/vi/Wn-_MyJV37E/0.jpg" />';

var abc = $('<div>' + newvalue + '</div>').find('*').each(function() {
}).html();

alert(abc);

</script>

I want abc to equal “newvalue”. But in my current code, abc is empty. Why?

This is what I truly want to do, but for example purposes, I left this blank above:

var whitelist = ['a','div','img', 'span'];
var abc = $('<div>' + newvalue + '</div>').find('*').each(function() {
    if($.inArray(this.nodeName.toLowerCase(), whitelist)==-1) {
        $(this).remove();
     }
}).html(); //abc is now sanitized!!!
  • 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-28T03:13:35+00:00Added an answer on May 28, 2026 at 3:13 am

    Breaking it down:

    var abc = $('<div>' + newvalue + '</div>') //Creates a div with an img element inside it
             .find('*')   //retrieves the img element
             .each(function() {}) //iterates over the jQuery set (only one img element)
             .html();  //returns the HTML serialization of the img element
                       //which has no contents, so it is an empty string
    

    You could call .parent().html(), which would retrieve the contents of the div you created.

    In your second example, you would want .end().html() which would pop the internal jQuery stack and get you back to the top-most div.

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

Sidebar

Related Questions

JS: The JS for client side validation of email field <script type=text/javascript src=http://code.jquery.com/jquery-latest.min.js> </script>
<script src=http://code.jquery.com/jquery-1.4.3.js type=text/javascript></script> <script src=https://github.com/tobia/CrossSlide/raw/master/jquery.cross-slide.min.js type=text/javascript></script> <script type=text/javascript> $(function(){ $(.imagedivholder).each(function(e){ $(this).crossSlide({ speed:45, fade:1 },[
I made this bookmarklet: javascript:(function(){var s=document.createElement('script');s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');document.getElementsByTagName('body')[0].appendChild(s);$('#hldIntMain').hide();$('#fadeBackground').hide();return false;})() Formatted code: // Add in jQuery var
My html code has many anchors and links such as : <script src=/Common/Scripts/jquery-1.4.4.min.js type=text/javascript></script>
I have the following code: <html> <head> <script type=text/javascript language=javascript src=jquery/jquery-1.5.1.js></script> <script type=text/javascript language=javascript
Here's a snippet of code from a shell script I have written: for src
UPDATE : I have the following code: <script type=text/javascript> function addScript(url) { var script
I'm trying to use enhance.js to load scripts only on desktops : http://dl.dropbox.com/u/426954/allora/index.html <script>
I use Zend Framework with ZfDebug ( http://code.google.com/p/zfdebug/ ) and a plugin Base64 Encode/Decode.
I want to edit following code.(This code is come from [http://stackoverflow.com/a/9280414/945688] <!DOCTYPE html> <html>

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.