1
2<h1>"My number: " <span id="myText"></span></h1>
3
4<script>
5
6 //You can use an IIFE (Immediately Invoked Function Expression)
7 (() => {
8 var number = "123";
9 document.getElementById("myText").innerHTML = number;
10 })();
11</script>
1var name="kieran";
2document.getElementById("output").innerHTML=name;
3
4and the html code would be:
5
6<p id="output"></p>
7
1// Plain Javascript Example
2var $jsName = document.querySelector('.name');
3var $jsValue = document.querySelector('.jsValue');
4
5$jsName.addEventListener('input', function(event){
6 $jsValue.innerHTML = $jsName.value;
7}, false);
8
9
10// JQuery example
11var $jqName = $('.name');
12var $jqValue = $('.jqValue');
13
14$jqName.on('input', function(event){
15 $jqValue.html($jqName.val());
16});