I'm curious about why this JQuery renders the full block HTML character:
var html = $('<div>█</div>');
$("body").append(html)
But this doesn't:
var html = $('█');
$("body").append(html)
Is there a way to render one single special character (by HTML or hex) without enclosing tags?
JSFiddle here: http://jsfiddle.net/G2Km8/2/
I think this is because JQuery treats your second case as a CSS selector rather than an HTML fragment. Since you probably don't have any elements matching "᫼" in your document, you are basically appending an empty set of elements to your body.
try using directly
$("body").append('█');
This prevents JQuery from having to guess if your string is and HTML fragment or a CSS selector. When passed a String, the append method assumes it is an HTML fragment.
You don't need the $ sign for the var
Check this:
http://jsfiddle.net/G2Km8/4/
$(document).ready(function(){
$("button").click(function(){
var html = "█";
$("body").append(html);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With