HTML text escape tips

HTML text escape tips
Today I saw a little trick for HTML text escaping on CSDN, which is very simple.

1. Use dom functions. First pass it to a DOM object as innerTEXT, then take the innerHTML attribute to get the escaped text.

For example:

div1.innerText = "<h1>title title....</h1>";

var str = div1.innerHTML; // "&lt;h1&gt;title title..."

2. Assuming there is a text context, you can perform $(x).text(context).html() on a jQuery object $(x), which will return an escaped text.

var str = $(x).text(context).html()

<<:  The difference between docker run and start

>>:  How to use the EXPLAIN command in SQL

Recommend

Detailed explanation of NodeJS modularity

Table of contents 1. Introduction 2. Main text 2....

Mysql classic high-level/command line operation (quick) (recommended)

Since I need to learn how to build servers and da...

Summary of constructor and super knowledge points in react components

1. Some tips on classes declared with class in re...

Nginx uses ctx to realize data sharing and context modification functions

Environment: init_worker_by_lua, set_by_lua, rewr...

Summary of Docker common commands and tips

Installation Script Ubuntu / CentOS There seems t...

MySQL query example explanation through instantiated object parameters

This article will introduce how to query data in ...

Complete steps to configure a static IP address for a Linux virtual machine

Preface In many cases, we will use virtual machin...

Example of how to deploy MySQL 8.0 using Docker

1. Refer to the official website to install docke...

Docker time zone issue and data migration issue

Latest solution: -v /usr/share/zoneinfo/Asia/Shan...

Vue realizes picture switching effect

This article example shares the specific code of ...

An example of how to implement an adaptive square using CSS

The traditional method is to write a square in a ...

SQL implementation of LeetCode (181. Employees earn more than managers)

[LeetCode] 181.Employees Earning More Than Their ...

Basic understanding and use of HTML select option

Detailed explanation of HTML (select option) in ja...