Javascript DOM HTML Kbd Object create

Introduction

We can create a <kbd> element via the document.createElement() method:

var x = document.createElement("KBD");

Click the button to create a KBD element with some text.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from www. j  a v a2 s .c o  m
  var x = document.createElement("KBD");
  var t = document.createTextNode("Keyboard input text");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related