Javascript DOM HTML TableHeader abbr Property get

Introduction

Return the value of the abbr attribute of a <th> element with id "myTh":

var x = document.getElementById("myTh").abbr;

Click the button to get the value of the abbr attribute of th with id "myTh".

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>/*from ww  w . jav a 2 s . com*/
</head>
<body>
<table>
  <tr>
    <th id="myTh" abbr="Make">Language</th>
    <th abbr="Model">Usage</th>
  </tr>
  <tr>
    <td>Bruder Toys</td>
    <td>Cross Country Vehicle</td>
  </tr>
</table>
<br>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myTh").abbr;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The abbr property sets or gets the value of the abbr attribute.

The abbr attribute sets a shorter version of the content in a header cell.

The abbr attribute does not show anything in ordinary web browsers.

It can be used by screen readers.

The abbr attribute accepts and returns a String value.




PreviousNext

Related