Javascript DOM HTML Kbd Object get

Introduction

The Kbd object represents an HTML <kbd> element.

We can access a <kbd> element via document.getElementById():

var x = document.getElementById("myKbd");

Click the button to set the color of the formatted text to red.

View in separate window

<!DOCTYPE html>
<html>
<body>
<kbd id="myKbd">Keyboard input</kbd>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from w ww  .  j  av  a 2 s . co  m*/
  var x = document.getElementById("myKbd");
  x.style.color = "red";
}
</script>

</body>
</html>



PreviousNext

Related