HTML DOM blockquote object


The HTML DOM blockquote basically represent the HTML element <blockquote>. The <blockquote> element does not add any quotation marks unlike the <q> tag. We can create and access <blockquote> properties with the help of the blockquote object.

Syntax

Following is the syntax for −

Creating the blockquote object −

var x = document.createElement("BLOCKQUOTE");

Example

Let us see an example of the blockquote object −

Live Demo

<!DOCTYPE html>
<html>
<body>
<p>Click on the below button to create a blockquote object</p>
<button onclick="createBloc()">CREATE</button>
<script>
   function createBloc() {
      var x = document.createElement("BLOCKQUOTE");
      var t = document.createTextNode("This is a random block quote.This is some sample text.");
      x.setAttribute("cite", "http://www.examplesite.com");
      x.setAttribute("id", "myQuote");
      x.appendChild(t);
      document.body.appendChild(x);
   }
</script>
</body>
</html>

Output

This will produce the following output −

On clicking CREATE −

In the above example −

First, we have created a button CREATE to call createBloc() function.

<button onclick="createBloc()">CREATE</button>

The function createBloc() uses the createElement() method of the document object to create a <blockquote> element. Then using the createTextNode() method of the document object we created a text node with some text inside it. Using the setAttribute() method we add some attributes like cite, and id to the above created <blockquote>element. The element is then finally appended as a child to the document body using its appendChild() method.

function createBloc() {
   var x = document.createElement("BLOCKQUOTE");
   var t = document.createTextNode("This is a random block quote.This is some sample text.");
   x.setAttribute("cite", "http://www.examplesite.com");
   x.setAttribute("id", "myQuote");
   x.appendChild(t);
   document.body.appendChild(x);
}

Updated on: 20-Feb-2021

121 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements