HTML DOM Kbd Object

HTMLWeb DevelopmentFront End Technology

The Kbd Object represents an inline element which displays monospace font by default.

Syntax

Following is the syntax −

Creating a <Kbd> element

var kbdObject = document.createElement(“KBD”)

Example

Let us see an example for Kbd object element −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Kbd Object</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Kbd Object</legend>
<label for="textSelect">Keyboard Input: </label>
<input id="textSelect" type="text" placeholder="John Doe">
<input type="button" onclick="convertKBD()" value="Check">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var textSelect = document.getElementById("textSelect");
   function convertKBD() {
      var kbdObject = document.createElement("KBD");
      var kbdText = document.createTextNode(textSelect.value);
      kbdObject.appendChild(kbdText);
      divDisplay.appendChild(kbdObject);
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Check’ button −

After clicking ‘Check’ button −

raja
Updated on 30-Jul-2019 22:30:26

Advertisements