Home  >  Article  >  Web Front-end  >  How to create new elements in HTML

How to create new elements in HTML

王林
王林forward
2020-04-18 17:25:412810browse

How to create new elements in HTML

There are three methods, as follows:

1. Through text/HTML

var txt1="<h1>Text.</h1>";

2. Through jQuery

var txt2=$("<h2></h2>").text("Text.");

3. Through JavaScript/DOM

var txt3=document.createElement("h3");
txt3.innerHTML="Text.";

(Recommended tutorial: html introductory tutorial)

The example code is as follows:

How to create new elements in HTML

The running results are as follows:

How to create new elements in HTML

Recommended video tutorial: html video tutorial

The above is the detailed content of How to create new elements in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete