br object
Inserts a line break.
The br tag is used to insert a line break into text.
Syntax:
Methods that return the object:
| document.createElement ("br") |
The base interface, through which you can add new functionalities to the br object, is the HTMLBRElement interface.
If you want to see the HTML objects by categories, please visit this page.
HTML page for this element: br |
Possible members:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example HTML code 1:
This example illustrates the use of the br element:
|
||||
Text without a line break Text with a <br /> line break |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example shows how to create a br element in JavaScript:
|
||||
<head> <script type="text/javascript"> function InsertLineBreaks () { var sentencesDiv = document.getElementById ("sentences"); var sentenceSpans = sentencesDiv.getElementsByTagName ("span"); for (var i = 1; i < sentenceSpans.length; i++) { var lineBreak = document.createElement ("br"); sentencesDiv.insertBefore (lineBreak, sentenceSpans[i]); } } </script> </head> <body> <button onclick="InsertLineBreaks ()">Insert line breaks into among sentences</button> <br /><br /> <div id="sentences"> <span>First sentence.</span> <span>Second sentence.</span> <span>Third sentence.</span> </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 3:
This example is similar to the previous one, but it uses a regular expression to create the new HTML content:
|
||||
<head> <script type="text/javascript"> function InsertLineBreaks () { var sentencesDiv = document.getElementById ("sentences"); var oldContent = sentencesDiv.innerHTML; var newContent = oldContent.replace (/\./g, ".<br />"); sentencesDiv.innerHTML = newContent; } </script> </head> <body> <button onclick="InsertLineBreaks ()">Insert a line break after each sentence</button> <br /><br /> <div id="sentences"> First sentence. Second sentence. Third sentence. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
External links:
User Contributed Comments