Display JavaScript Variables in HTML Without document.write



Use Element.innerHTML in JavaScript to display JavaScript variables in an HTML page without document.write.

You can try to work through the following code snippet −

var $myName = document.querySelector('.name');
var $jsValue = document.querySelector('.jsValue');

$myName.addEventListener('input', function(event){
   $jsValue.innerHTML = $myName.value;
}, false);
Updated on: 2020-06-24T06:42:02+05:30

344 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements