HTML DOM Italic Object

HTMLWeb DevelopmentFront End Technology

The HTML DOM Italic Object represents an <i> element which displays text in italic.

Syntax

Following is the syntax −

Creating an <i> element

var italicObject = document.createElement(“I”)

Example

Let us see an example for Italic object element −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Italic Object</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Italic Object</legend>
<label for="textSelect">Formatter: </label>
<input id="textSelect" type="text" placeholder="John Doe">
<input type="button" onclick="convertItalic()" value="Check">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var textSelect = document.getElementById("textSelect");
   function convertItalic() {
      var italicObject = document.createElement("I");
      var italicText = document.createTextNode(textSelect.value);
      italicObject.appendChild(italicText);
      divDisplay.appendChild(italicObject);
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Check’ button −

After clicking ‘Check’ button −

raja
Published on 29-Jul-2019 11:41:39
Advertisements