address LINK object in the HEAD section

V

VK

Having HEAD section like that:

<head>

<title>Foo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<link
title="linkObject"
rel="Alternate Appendix"
type="text/plain"
href="data.txt"
charset="iso-8859-1"
hreflang="en-US">

</head>

what would be the most realible way to get "linkObject" reference?

var roof = document.getElementsByTagName('HEAD')[0];
// ?
 
T

Thomas 'PointedEars' Lahn

VK said:
Having HEAD section like that:

<head>

<title>Foo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<link
title="linkObject"
rel="Alternate Appendix"
type="text/plain"
href="data.txt"
charset="iso-8859-1"
hreflang="en-US">

</head>

what would be the most realible way to get "linkObject" reference?

var roof = document.getElementsByTagName('HEAD')[0];
// ?

Replacing `title=' with `id=' and using Document::getElementById().


PointedEars
 
V

VK

Thomas said:
Replacing `title=' with `id=' and using Document::getElementById().

Are ID's formally allowed for LINK? Or for other elements in the
non-rendering section (HEAD) I did not find this attribute listed
neither in W3C nor in MSDN. From the other side TITLE is required by
W3C for alternate content links.

Not to say I technically care too much but for some reasons I want to
have this LINK usage free of any "hacking model" accusations. Unusual -
yes, but fully standard compliant.
 
T

Thomas 'PointedEars' Lahn

VK said:
Are ID's formally allowed for LINK? Or for other elements in the
non-rendering section (HEAD) I did not find this attribute listed
neither in W3C nor in MSDN.

You must have a different "W3C" and "MSDN" than I have ;-)

The `id' attribute is allowed for "All elements but BASE,
HEAD, HTML, META, SCRIPT, STYLE, TITLE".
See <URL:http://www.w3.org/TR/html4/index/attributes.html>

,-<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/id.asp>
|
| Applies To
| [...] LABEL, LEGEND, LI, LINK, LISTING, [...]
^^^^
The (X)HTML DTDs clearly state the `link' element has the `id' attribute:

<URL:http://www.w3.org/TR/REC-html32#link>

<http://www.w3.org/TR/html4/struct/links.html#edef-LINK>
(note the `%attrs;' entity reference and follow the links
<URL:http://www.w3.org/TR/html4/sgml/dtd.html#attrs>
<URL:http://www.w3.org/TR/html4/sgml/dtd.html#coreattrs>)

<URL:https://www.cs.tcd.ie/15445/15445.html#DTD>
(search for "ATTLIST link")

<URL:http://www.w3.org/TR/xhtml1/dtds.html#dtdentry_xhtml1-strict.dtd_link>
(search for "ATTLIST link", note the `%attrs;' entity reference and follow
the links)

The `title' attribute, however, should provide for a short description of
the element.

From the other side TITLE is required by W3C for alternate content links.

How do you got that idea?

Not to say I technically care too much

But you should, for your own sake and that of users of your content.
but for some reasons I want to have this LINK usage free of any "hacking
model" accusations. Unusual - yes, but fully standard compliant.

Accessing the `id' attribute value is sufficiently un"hack"ish :)


PointedEars
 
M

mrHoo

function getElementByAttribute(tagn,attrib,str){
var A=document.getElementsByTagName(tagn);
var O;
var L=A.length;
for(var i=0;i<L;i++){
var tem=A;
if(tem.getAttribute(attrib)&& tem.getAttribute(attrib)==str){
O=tem;
break;
}
}
return O;
}
 
M

mrHoo

function getElementsByAttribute(tagn,attrib,str){
var A=document.getElementsByTagName(tagn);
var O=new Array();;
var L=A.length;
for(var i=0;i<L;i++){
var tem=A;
if(tem.getAttribute(attrib)){
if(str) tem.getAttribute(attrib)==str) O.push(tem);
else O.push(tem);
}
return O;
}
// In your case you can call: getElementsByAttribute('link','title',str)
(str is whatever you want to match)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top