Skip to main content

How come this JQuery code returns nothing?





<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!!!




Comments

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?