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

custom tags and elements

P: n/a
Hi,

I would like to include extra "hidden" information in a generated HTML page
that can be used by javascript functions.

I realise that most browsers seem to ignore any tags and attributes they
don't understand, but from what I can tell the standards do not allow me to
make up my own tags or attributes as they will fail validation.

is there any standard element name that can be used for such a purpose i.e.
passes validation but never produces any output (and ideally allows nested
elements to be rendered normally too)

Andy


Dec 5 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Andy Fish wrote:
I would like to include extra "hidden" information in a generated HTML page
that can be used by javascript functions.

I realise that most browsers seem to ignore any tags and attributes they
don't understand, but from what I can tell the standards do not allow me to
make up my own tags or attributes as they will fail validation.

is there any standard element name that can be used for such a purpose i.e.
passes validation but never produces any output (and ideally allows nested
elements to be rendered normally too)
If you want to put extra data into a web page for use by javascript why
not put it inside a SCRIPT element, probably in a structure made up of
Array and Object literals (as anything that can be represented with a
mark-up tree can also be represented in such a form).

Richard.

Dec 5 '06 #2

P: n/a
"Andy Fish" <aj****@blueyonder.co.ukwrote:
>I would like to include extra "hidden" information in a generated HTML page
that can be used by javascript functions.

I realise that most browsers seem to ignore any tags and attributes they
don't understand, but from what I can tell the standards do not allow me to
make up my own tags or attributes as they will fail validation.

is there any standard element name that can be used for such a purpose i.e.
passes validation but never produces any output (and ideally allows nested
elements to be rendered normally too)
What is it that you are actually trying to do?

--
Spartanicus
Dec 5 '06 #3

P: n/a

Andy Fish wrote:
I would like to include extra "hidden" information in a generated HTML page
that can be used by javascript functions.
Then put it in JavaScript.

I realise that most browsers seem to ignore any tags and attributes they
don't understand,
No, they ignore unknown attributes. They will still process unknown
tags (they show you their content) even if the "tag" appears not to
have any effect. This behaviour is pretty reliable.

but from what I can tell the standards do not allow me to
make up my own tags or attributes as they will fail validation.
You'll be able to do this cleanly with XML and namespacing, but that's
still a long way off.
is there any standard element name that can be used for such a purpose
In general, it's enough to use the existing elements and almost always
to stick with the standard attributes too. You can achieve most of what
you need with the class or id attributes. These values can then be
lookup indexes into JavaScript arrays for more detail. You can even use
anodyne elements like <divor <span>, added where necessary just as
carriers for these attributes.

I'd happily add attributes if I really needed to, or it made the code
clearer. I wouldn't add elements though.

Dec 5 '06 #4

P: n/a
thanks andy (and others) for the replies

I guess the best solution in the general case would be to store extra stuff
in javascript structures indexed by element ids. I hadn't really thought of
this.

in this case, I just want to store a single extra string value alongside
some of the <atags, so I will use my own custom attribute.

Andy

"Andy Dingley" <di*****@codesmiths.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
>
Andy Fish wrote:
>I would like to include extra "hidden" information in a generated HTML
page
that can be used by javascript functions.

Then put it in JavaScript.

>I realise that most browsers seem to ignore any tags and attributes they
don't understand,

No, they ignore unknown attributes. They will still process unknown
tags (they show you their content) even if the "tag" appears not to
have any effect. This behaviour is pretty reliable.

>but from what I can tell the standards do not allow me to
make up my own tags or attributes as they will fail validation.

You'll be able to do this cleanly with XML and namespacing, but that's
still a long way off.
>is there any standard element name that can be used for such a purpose

In general, it's enough to use the existing elements and almost always
to stick with the standard attributes too. You can achieve most of what
you need with the class or id attributes. These values can then be
lookup indexes into JavaScript arrays for more detail. You can even use
anodyne elements like <divor <span>, added where necessary just as
carriers for these attributes.

I'd happily add attributes if I really needed to, or it made the code
clearer. I wouldn't add elements though.

Dec 5 '06 #5

P: n/a
Andy Fish wrote:
is there any standard element name that can be used for such a purpose i.e.
passes validation but never produces any output (and ideally allows nested
elements to be rendered normally too)
<input type="hidden" id="secretid" name="my-hidden-name"
value="my-hidden-data">

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Dec 5 '06 #6

P: n/a

Andy Dingley wrote:
In general, it's enough to use the existing elements and almost always
to stick with the standard attributes too. You can achieve most of what
you need with the class or id attributes.
Read this thread for an interesting example of the technique (and use
of the rel attribute)
http://groups.google.co.uk/group/alt...8e7028fa7fa1/#

Dec 5 '06 #7

P: n/a
In our last episode,
<Zn******************@text.news.blueyonder.co.uk >,
the lovely and talented Andy Fish
broadcast on comp.infosystems.www.authoring.html:
Hi,
I would like to include extra "hidden" information in a generated HTML page
that can be used by javascript functions.
I realise that most browsers seem to ignore any tags and attributes they
don't understand, but from what I can tell the standards do not allow me to
make up my own tags or attributes as they will fail validation.
is there any standard element name that can be used for such a purpose i.e.
passes validation but never produces any output (and ideally allows nested
elements to be rendered normally too)
DIV and SPAN are the general block and inline elements respectively. To the
best of my knowledge, there is not a general empty element, although I have
long thought it would be a good idea if there were.

There are some places where absolutely nothing except white space or
comments is allowable. For example, you cannot put anything in TR
except TH or TD, so you cannot put any other naked element in TR, but I
think in most cases you can use DIV or SPAN if you are care to choose
which is allowable in the context. You cannot, of course, just make up
attributes, but you certainly can code information in CLASS and ID.

As for "never produces any output," it isn't clear to me what that means.
Do you mean you don't want the contents of the element rendered? In that
case you can style the element for display: none, but of course that doesn't
hide the contents from the browser, it only suggests that styles-enabled
browsers not render it. Or do you mean that you do not want the element to
be rendered differently because of the element? In that case, simply don't
style the element and, if you have chosen rightly between DIV and SPAN,
the appearance of the rendered document will not be changed.
--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Cole's Law: Thinly sliced cabbage.
Dec 5 '06 #8

P: n/a
In article <Rf******************@text.news.blueyonder.co.uk >,
"Andy Fish" <aj****@blueyonder.co.ukwrote:
in this case, I just want to store a single extra string value alongside
some of the <atags, so I will use my own custom attribute.
After finding too many problems with trying to use an element for a blog
entry, I used the title attribute in my anchors to store information
about each entry (for potential future use by an indexing system). While
using title means the title contents are normally visible if you hover,
in this case it isn't a problem, since there is no reason someone
browsing a blog shouldn't be able to see the categories I was using.

<h3><a name="20061202a" title="categories computers media">Sony being
Weird</a></h3>

Seems valid, and doesn't seem to me to warp semantics too much.

--
http://www.ericlindsay.com
Dec 7 '06 #9

P: n/a
Andy Fish wrote:
is there any standard element name that can be used for such a purpose
i.e. passes validation but never produces any output (and ideally allows
nested elements to be rendered normally too)
form. It can have input[type="hidden"] descendants where you can store your
data, and it can also have nested elements as descendants. Might not be
pretty, but works smoothly as long as nobody submits the form without a
submit button.

You could also use a `meta' element.

Note that these are not general recommendations for a solution. I am merely
pointing out the options you have within the given constraints.
PointedEars
--
Let us not judge others because of their religion, color or nationality.
We are all just human beings living together on this planet. (poehoe.de)
Dec 11 '06 #10

P: n/a

Thomas 'PointedEars' Lahn wrote:
You could also use a `meta' element.
Not in the <bodyof the HTML document you can't. If you can't do that,
then you lose the direct link between usage and annotation and have to
use an indirect reference. If you have to do this, then it's easier to
store the annotation in JavaScript code directly and save having to
retrieve it from the DOM.

Dec 11 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.