By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

slashes in HTML tags in JavaScript

P: n/a
I have noticed with various codes that the slashes are not consistent. Is there a reason for this.

For example

</td>
</\td>
<\/td>
<td />

what is the difference with these tags?
also, tags that do not normally have a slash in them, such as the <br> command I have seen with a
slash at the end, such as <br />
Pardon my ignorance, but is there a reason for the extra slashes?
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Treetop wrote:

Well, that's HTML and not JavaScript.
But anyway.

</td> <-- closing Tag of <td>
</\td> <-- doesn't exist in HTML/XHTML
<\/td> <-- doesn't exist also
<td /> <-- represents an empty element, used in XML and XHTML
to represent an element like <td></td> with no content.
also, tags that do not normally have a slash in them,
such as the <br> command I have seen with a
slash at the end, such as <br />


Like mentioned yet, <br> is an empty element with no content.
Never. In good old HTML you can write just <br>. In XHTML and
XML (well, in XML you can use any element names, so theoretically
you could give content to a <br> element) you have to write
<br />

The backslash isn't used in the Markup Languages like HTML,
XHTML or XML or similars, but he is used in JavaScript (and other
languages, so in PHP, too, f.e.) to escape certain characters
like quotations, line breaks, tabs, etc.

line break: \n
tab: \t
quotations: \"

You can escape the slash, too. I think you don't have to,
but you can. So this:

alert('<\/td>');

will give you an alert showing just:

</td>

and that's the normal closing tag for a <td> before.

This sample in javascript: </\td> would return you a string
like this:

</ d>

(with a tab between / and d, becaus \t is used for the
tab character.

I hope I helped you ;-)

Saludo
Paul.
Jul 20 '05 #2

P: n/a
On Tue, 07 Oct 2003 15:33:46 GMT, "Treetop" <tr*****@netfront.net>
wrote:

[You got a good response to the others]
also, tags that do not normally have a slash in them, such as the <br>
command I have seen with a slash at the end, such as <br />

Pardon my ignorance, but is there a reason for the extra slashes?


Hype Monkeys - some people heard about XHTML and stuck them in,
probably best avoided and sticking with HTML 4.01 until we see some
real implementations.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #3

P: n/a
Thanks for the info. I would rather code in HTML 3 or 4. I just wanted to make sure that I didn't
have to do anything special with my HTML as I start to learn JavaScript, such as the <br />.
"Paul Wellner Bou" <pa**********@united-scripts.com> wrote in message
news:op**************@news.individual.net...
Treetop wrote:

Well, that's HTML and not JavaScript.
But anyway.

</td> <-- closing Tag of <td>
</\td> <-- doesn't exist in HTML/XHTML
<\/td> <-- doesn't exist also
<td /> <-- represents an empty element, used in XML and XHTML
to represent an element like <td></td> with no content.
also, tags that do not normally have a slash in them,
such as the <br> command I have seen with a
slash at the end, such as <br />


Like mentioned yet, <br> is an empty element with no content.
Never. In good old HTML you can write just <br>. In XHTML and
XML (well, in XML you can use any element names, so theoretically
you could give content to a <br> element) you have to write
<br />

The backslash isn't used in the Markup Languages like HTML,
XHTML or XML or similars, but he is used in JavaScript (and other
languages, so in PHP, too, f.e.) to escape certain characters
like quotations, line breaks, tabs, etc.

line break: \n
tab: \t
quotations: \"

You can escape the slash, too. I think you don't have to,
but you can. So this:

alert('<\/td>');

will give you an alert showing just:

</td>

and that's the normal closing tag for a <td> before.

This sample in javascript: </\td> would return you a string
like this:

</ d>

(with a tab between / and d, becaus \t is used for the
tab character.

I hope I helped you ;-)

Saludo
Paul.

Jul 20 '05 #4

P: n/a
Paul Wellner Bou <pa**********@united-scripts.com> writes:
You can escape the slash, too. I think you don't have to,
but you can. So this:

alert('<\/td>');

will give you an alert showing just:

</td>


According to the HTML specification, you do have to insert the
backslash.

The contents of a script tag is not interpreted as HTML, so if you
have "<td>" in the code, it is just a Javascript string. However,
the terminating </script> must be interpreted as HTML.

The specification actually says that the script tag is terminated
at the first occurence of "</" (the end-tag-start-marker). To avoid
premature termination, the easiest way, and recommended in the
HTML specification, is to escape the slash.

In practice, most current browsers are forgiving, and won't stop at
the first "</", but will only stop at a script end tag, "</script>".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

P: n/a
JRS: In article <79******************************@news.teranews.co m>,
seen in news:comp.lang.javascript, Treetop <tr*****@netfront.net> posted
at Tue, 7 Oct 2003 15:33:46 :-

<\/td>


In a javascript string, </td>, etc., annoy at least one HTML checker
(W3/sourceforge's TIDY), whereas <\/td>, etc., do not, and work just as
well.

All pages should be HTML-checked, since it is a good way of finding
typos in the HTML language, and a page with a typo cannot be relied on
to render as you would wish in some or all browsers. Neither can other
pages, but having no typos helps.

One does not want even harmless errors reported, since if that is
allowed there is a risk of missing potentially harmful ones.

For those in a recent thread, "Q re white paper on Escaping characters":
that may be an example of backslash followed by a non-listed character,
which is supposed to be deprecated.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.