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

How to create new elements in HTML

王林
Release: 2020-04-18 17:25:41
forward
2914 people have browsed it

How to create new elements in HTML

There are three methods, as follows:

1. Through text/HTML

var txt1="<h1>Text.</h1>";
Copy after login

2. Through jQuery

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

3. Through JavaScript/DOM

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

(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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template