SoFunction
Updated on 2025-03-01

Three ways to read data from a database and output it to an html tag

Maybe many people read data from the database without the data being html tag, but maybe one day you will find that when we need to output it as html tag, the compiler will automatically output it into a string. This is how we can do it.

Method 1:

The most common method is to use JS or JQ

JQ:

$("#div").html("<span>I am HTML code</span>");

JS:

var dobj=("div");
 = "<span>I am HTML code</span>";

Method 2:

When you find that the data read from the database is not good, you can try it

$("#div").html(“@(I'm in the databaseHTMLCode)”);