473,414 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

slashes in HTML tags in JavaScript

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
5 11381
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: chotiwallah | last post by:
i have a little database driven content managment system. people can load up html-docs. some of them use ms word as their html-editor, which resultes in loads of "class" and "style" attributes -...
15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
13
by: nobody | last post by:
Hello all, I've searched just about everything and although I can see that other people are having problems, but theirs don't seem to relate, so in a last ditch attempt, my posting! Script...
2
by: Jamiil | last post by:
This is the first time I am ever using JavaScript, I am not even eloquent in HTML, and all I am is someone who has Microsoft/Netscape Webpage developers. What I am trying to say is that I am not an...
5
by: acord | last post by:
Hi, I m getting annoying display problem when placing javascript tags in a html page. Should the javasscript tags placed at the beginning of a html page before anything start? or placed between...
3
by: Alex | last post by:
Hello. First, with AJAX I will get a remote web page into a string. Thus, a string will contain HTML tags and such. I will need to extract text from one <span> for which I know the ID the inner...
1
by: since | last post by:
I figured I would post my solution to the following. Resizable column tables. Search and replace values in a table. (IE only) Scrollable tables. Sortable tables. It is based on a lot...
53
by: brave1979 | last post by:
Please check out my javascript library that allows you to create any layout for your web page, nested as deep as you like, adjusting to width and height of a browser window. You just describe it in...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.