HTML DOM Span object

The HTML DOM span object is associated with the HTML element. We can create and access span element using the createElement() and getElementById() method respectively.

Syntax

Following is the syntax for ?

Creating a span object ?

var a = document.createElement("SPAN");

Example

Let us look at an example for the span object ?



Span object example

Create a span element by clicking the below button

This is some text inside a p element

Output

This will produce the following output ?

On clicking the CREATE button ?

Updated on: 2026-03-11T22:50:45+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements