document.write("</br>"); was written on the board by our teacher as an example for how to make a new line with javascript. In my experience as a web developer I have never seen this slash in front of br. But when I test it with chrome web development tools it works and it simply converts </br> to <br>. Yet I do not understand why.
Asked
Active
Viewed 38 times
0
crazy
- 57
- 1
- 11
1 Answers
2
document.write("</br>"); does not produces valid HTML.
However it is frequent to observe browser-side HTML error correction mechanisms. In the wild, most small invalid HTML errors get corrrected and valid HTML ends up in the DOM: closing tags at the end of a file that can be deduced from the rest of the content, <br/> or <br></br> instead of <br>, <input ... /> instead of <input ... >, and so on.
Different browsers offer different error correction mechanisms and they don't follow any particular standard so it's always good to avoid relying on them.
Nino Filiu
- 16,660
- 11
- 54
- 84
` is valid, but `` is not – malifa May 08 '19 at 19:48
` would actually be invalid too. – Jonas Wilms May 08 '19 at 19:50