Javascript Reference - HTML DOM Quote Object








The Quote object represents an HTML <q> element.

Standard Properties and Events

The Quote object supports the standard properties and events.

Quote Object Properties

Property Description
cite Sets or gets the cite attribute of a quotation

Example

We can access a <q> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<q id="myQuote" cite="http://www.example.com">quote</q>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from   ww  w .j  av a  2s .co  m-->
    var x = document.getElementById("myQuote").cite;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create a <q> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--  w  w  w.  ja v a 2s.c  o m-->
    var x = document.createElement("QUOTE");
    var t = document.createTextNode("text");
    x.setAttribute("cite", "http://www.example.com");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows: