JSFiddle - React, Tailwind, and code Playground

by dmethvin

HTML

<div id='js'></div>
<div id='jqtext'></div>
<div id='jqstring'></div> 
<div id='jqhtml'></div>

CSS

div{
    min-height:20px; 
    border: 1px solid black;
    margin-bottom: 5px;
    padding: 5px;
}

JavaScript

String.prototype.test = function(){
    console.log(typeof this);
    console.log(this.constructor == String);
    return this.toString();
};
var myString = "<b>Hello World</b>";
myString = myString.test();

document.getElementById('js').innerHTML = myString; //works without changing the type
$('#jqtext').text(myString); //so does $.text()
$('#jqstring').html(myString+" is an "+typeof myString); //only works when forced as a string
$('#jqhtml').html(myString);