The Italic object represents an HTML <i> element.
The Italic object supports the standard properties and events.
We can access an <i> element by using getElementById().
<!DOCTYPE html>
<html>
<body>
<i id="myItalic">this italic text</i>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w w w .j a v a 2 s. co m-->
var x = document.getElementById("myItalic");
x.style.color = "red";
x.style.fontSize = "x-large";
}
</script>
</body>
</html>
The code above is rendered as follows:
We can create an <i> element by using the document.createElement() method.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- w w w. java 2s .com-->
var x = document.createElement("I");
x.style.color = "red";
x.style.fontSize = "x-large";
var t = document.createTextNode("this is a test");
x.appendChild(t);
document.body.appendChild(x);
}
</script>
</body>
</html>
The code above is rendered as follows: