
A Smiley can be an icon. However, you can also use a simple ASCII or a Unicode to insert a Smiley in your HTML page. For example,
<html>
<head>
<title>Insert a Smiley</title>
</head>
<body style='font-size:30px;'>
<div>Hello world ☺</div>
</body>
</html>Here's a list of other Symbols that you can add in your web page.
The Unicode or the Decimal code 9786, prefixed with &#, shows a white Smiley after the string Hello world. It also has a hex code value ☺.
Now let’s see how you can use the above code dynamically inside your JavaScript code.
<html>
<head>
<title>Insert a Smiley using JavaScript</title>
</head>
<body>
<input type='button' value='Now Smile' onclick='smile()' />
<p id="msg" style='font-size:100px;'></p>
</body>
<script>
function smile() {
var msg = document.getElementById('msg');
msg.innerHTML = '☺';
}
</script>
</html>It is simple. All you have to do is, assign the code ☺ to the element.
More Symbols using HTML Unicode
As I said in the beginning, there are many unique HTML codes for different symbols. The script below shows many other interesting symbols in the Range 9728 and 10000.
<html>
<head>
<title></title>
</head>
<body>
<input type='button' value='More Characters' onclick='showSymbols()' />
<p id="msg" style='font-size:50px;'></p>
</body>
<script>
function showSymbols() {
var msg = document.getElementById('msg');
msg.innerHTML = 'Smile ' + '☺';
for (var i = 9728; i <= 10000; i++) {
msg.innerHTML = msg.innerHTML + '<br />' + ' &#' + i + '; ( ' + i + ' )';
}
}
</script>
</html>