+ 1

text in HTML

how do I make an element a text in HTML? e.g let's say I want to run the code, I will see <div> as a text when I run the code. Pls how do I do that?

27th Apr 2020, 11:34 AM
Uche
Uche - avatar
5 Respuestas
+ 5
Using UTF-8 Miscellaneous Symbols, like this: &lt;div&gt; https://www.w3schools.com/charsets/ref_utf_symbols.asp
27th Apr 2020, 11:50 AM
Farhan
Farhan - avatar
+ 4
Farhan🇮🇳☪️ &lt; &gt; and others (&amp; ...) are not "UTF-8 Miscellaneous Symbols" but HTML Entities ^^ However, they map special chars to name code for some as them, and any utf8 chars with the numeric form: &#xxxx; where xxxx is the utf-8 code point that you want to target ;P (that's why I'm not fan of w3s: even if they have some good ressources, they are mixed with approximative and/or obsolete informations :( ) Lasly right, and that's a simplest and more efficient ways to convert "unsafe" html chars... but you could do the same (as for quite all jQuery features todays) with pure javascript thanks to the HTMLElement.textContent attribute ;) Uche even if you do not plan to insert your text dynamically, it's very easy to build a minimal translate tool with a textarea where you could copy/paste the text to be converted in "safe" html string with a hidden <div> (or any non-empty classic element but not form element) to wich you assign the text value to the .textContent attribute, then update the text value
27th Apr 2020, 6:23 PM
visph
visph - avatar
+ 2
<xmp><div></xmp>
27th Apr 2020, 6:58 PM
Solo
Solo - avatar
+ 1
If you want add HTML tag like a simile text in your div text by Jquery you can use .text insteadof .html method. $(function() { $("#yourdivid").text("<p/>hello</p>"); });
27th Apr 2020, 12:06 PM
Lasly
Lasly - avatar
0
Vasiliy <xmp> is obsolete and deprecated since html3.2 and was never implemented in a consistent way ^^ And if you need to output </xmp> you will get mess in your html structure ;P Try just this to convince you: <xmp><div>foo</div></xmp><span>bar</div></xmp> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/xmp
27th Apr 2020, 7:08 PM
visph
visph - avatar