The Kbd object represents an HTML <kbd> element.
The Kbd object supports the standard properties and events.
We can access a <kbd> element by using getElementById().
<!DOCTYPE html>
<html>
<body>
<kbd id="myKbd">Keyboard input</kbd>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w w w.j a va2s.c o m-->
var x = document.getElementById("myKbd");
x.style.color = "blue";
}
</script>
</body>
</html>
The code above is rendered as follows:
We can create a <kbd> element by using the document.createElement() method.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- ww w. j av a 2 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>
The code above is rendered as follows: