Lee
Lee

Reputation: 11

JavaScript document.write br

How do you write in JavaScript "<br>"? I don't want it to break and go to the next line, I just want the html tag to be written. Something like: "the break tag in html is ..."

Example of what I want below.

<script type = "text/javascript">
    document.write('"<br>"');
</script>

Upvotes: 1

Views: 1631

Answers (2)

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

You could use HTML entities of < and > :

< : &lt;
> : &gt;

&lt;br&gt; = <br>

Hoep this helps.


document.write("I don't want &lt;br&gt; to break and go to the next line");

Upvotes: 0

Nina Scholz
Nina Scholz

Reputation: 386570

Just use HTML entities.

Character  Entity   Note
---------  -------  ----------------------------------------------------------------
    &      &amp;    Character indicates the beginning of an entity. 
    <      &lt;     Character indicates the beginning of a tag 
    >      &gt;     Character indicates the ending of a tag 
    "      &quote;  Character indicates the beginning and end of an attribute value. 

document.write('The break tag in html is &lt;br&gt;.');

Upvotes: 2

Related Questions