How to Create a Span Element in JavaScript?

Estimated read time 1 min read

Here is an example to create a span element in JavaScript:

var span = document.createElement("span");
span.innerHTML = "This is a span element";

This code creates a new span element using the document.createElement method. The innerHTML property is used to set the text content of the span. The appendChild method is then used to add the new span element to the end of the body of the document. This will cause the text “This is a span element” to be displayed on the web page.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply