How to make a text italic in JavaScript?

To make italic text, we have two methods, first one is style.fontStyle, and the italics() method.

The property sets or returns whether the style of the font is normal, italic, or oblique.

Method 1: Using style.fontStyle

HTML

<!DOCTYPE html>
<html>
<body>

<p id="text_id">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever</p>


<button onclick="myfunction()">make italic</button>



</body>
</html>

javascript

function myfunction() {
 
   	document.getElementById("text_id").style.fontStyle = "italic";
         
}

Method 2: Using  italics() method

We can also use the javascript italics() method. The italics() method creates an <i> An HTML element that causes a string to be italic.

<html>
   <head>
      <title>JavaScript String italics() Method</title>
   </head>

   <body>
      <script>
         var str = new String("Demo Text");
         document.write(str.italics());
         alert(str.italics());
      </script>
   </body>
</html>