473,804 Members | 3,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementsByTa gName select element weirdness

Hi,

On both Opera and Firefox, getElementsByTa gName doesn't find anything
apart from <optionelemen ts inside a select element. Why is this?
Here's a page that demonstrates this behaviour. I'd have thought the
correct behaviour would be to show "count: 1" but instead, you get
"count: 2".

Is this because only <option>s <select>s?

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
</title>
<script type='text/javascript'>
window.onload = function() {
var elems = document.getEle mentsByTagName( "xref");
alert("count: " + elems.length);
};
</script>
<style type='text/css'></style>
</head>
<body>
<div id='banner'>
<h1>
</h1>
</div>
<div id='content'>
<select>
<xref ref="1"/>
</select>
</div>
</body>
</html>
Cheers,
Andy
Aug 2 '08 #1
5 4553
Andy Chambers wrote:
On both Opera and Firefox, getElementsByTa gName doesn't find anything
apart from <optionelemen ts inside a select element. Why is this?
You are trying to use extended XHTML, and your markup is not Valid.[1] The
"Extensible " in XHTML does _not_ mean "anything goes"; if you want to extend
XHTML, you need to declare a namespace for all non-XHTML elements and
attributes and a DTD or a Schema that declares these elements and
attributes. And of course you must comply with the XHTML DTD (that you
missed to declare here), which says in your case (assuming XHTML 1.0
Transitional or Strict):

| <!ELEMENT select (optgroup|optio n)+ <!-- option selector -->

Meaning that an XHTML `select' element must contain at least one of
`optgroup' or `option' elements.
[...]
Is this because only <option>s <select>s?
Parse error.
<html xmlns="http://www.w3.org/1999/xhtml">
This declares the XHTML namespace as the default namespace.
[...]
var elems = document.getEle mentsByTagName( "xref");
[...]
<body>
[...]
<select>
<xref ref="1"/>
</select>
[...]
</body>
</html>
Therefore, you need to use namespace-based accessor methods in an XHTML
document. Suppose your `xref' element was declared in
<http://achambers.me.uk/dtds/ac.dtdlike this:

...
<!ELEMENT select (optgroup|optio n|xref)+>
...
<!ELEMENT xref EMPTY>
<!ATTLIST xref
ref CDATA #REQUIRED
>
...

And used like this:

<DOCTYPE html PUBLIC "-//AChambers//DTD XHTML 1.0 plus ACMarkup//EN"
"http://achambers.me.uk/dtds/xhtml1-acmarkup.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
xmlns:ac="http://achambers.me.uk/acmarkup"
xml:lang="en">
...
<body>
...
<ac:xref ref="1"/>
...
</body>
</html>

You would access it like this:

var elem = document.getEle mentsByTagNameN S(
"http://achambers.me.uk/acmarkup", "xref")[0];
PointedEars
___________
[1] <http://validator.w3.or g/>
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Aug 2 '08 #2
Thomas 'PointedEars' Lahn wrote:
[...] Suppose your `xref' element was declared in
<http://achambers.me.uk/dtds/ac.dtdlike this:

[...]
And used like this:

<DOCTYPE html PUBLIC "-//AChambers//DTD XHTML 1.0 plus ACMarkup//EN"
"http://achambers.me.uk/dtds/xhtml1-acmarkup.dtd">
[...]
Those two URIs must be the same, of course.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Aug 2 '08 #3
Thomas 'PointedEars' Lahn wrote:
<DOCTYPE html PUBLIC "-//AChambers//DTD XHTML 1.0 plus ACMarkup//EN"
"http://achambers.me.uk/dtds/xhtml1-acmarkup.dtd">
[...]

Those two URIs must be the same, of course.
So does the browser actually lookup the DTD and validate the document
before loading it? Does it have to be a DTD or could it be something
else that defines your allowable elements (e.g. relaxng or w3c
schema).

Is it possible to extend plain old html in this way or is that the
whole point of xhtml?

Cheers,
Andy
Aug 2 '08 #4
Andy Chambers wrote:
On both Opera and Firefox, getElementsByTa gName doesn't find anything
apart from <optionelemen ts inside a select element. Why is this?
Here's a page that demonstrates this behaviour. I'd have thought the
correct behaviour would be to show "count: 1" but instead, you get
"count: 2".
Do you serve the document as text/html or as application/xhtml+xml or
application/xml or text/xml?
Why do you say "doesn't find anything" if count is 2?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 3 '08 #5
Andy Chambers wrote:
Thomas 'PointedEars' Lahn wrote:
>><DOCTYPE html PUBLIC "-//AChambers//DTD XHTML 1.0 plus ACMarkup//EN"
"http://achambers.me.uk/dtds/xhtml1-acmarkup.dtd">
[...]
Those two URIs must be the same, of course.

So does the browser actually lookup the DTD and validate the document
before loading it? Does it have to be a DTD or could it be something
else that defines your allowable elements (e.g. relaxng or w3c
schema).

Is it possible to extend plain old html in this way or is that the
whole point of xhtml?

That is getting OT for this news group, though some here likely know the
answer. Try:

news:comp.infos ystems.www.authoring.html
But beware, some there have a passionate dislike of XHTML (which is not
a hint to not post, only to be tolerant of some replies you'll get). :-)
--
Rob
Aug 4 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4527
by: 2obvious | last post by:
This is a pipe dream, I realize, but I'm trying to emulate the functionality of the W3C DOM-supported document.getElementsByTagName method under the very nightmarish Netscape 4. Through some sleuthing, I was able to find what serves as a document.getElementById emulator at http://www.xs4all.nl/~ppk/js/dhtmloptions.html#versionb. (Below is the code; this clever algorithm is painstakingly explained at the site above.)
4
1992
by: norfleet | last post by:
hi folks, OK, so let's say, for example, I have a bit of HTML that looks like this: <td class="regular1b" valign="top"> <a href="notfound.html"><span class="list5"><b>Lecture V</b></span></a> </td>
23
15608
by: Michel Bany | last post by:
I am trying to parse responseXML from an HTTP request. var doc = request.responseXML; var elements = doc.getElementsByTagName("*"); the last statement returns an empty collection when running from IE6. It returns the expected collection when running under Firefox or Mozilla. Anybody can explain ? Michel.
3
21926
by: hutch | last post by:
Hi, I'm making use of this VERY useful function for a so called 'standards compliant' replacement for target="_blank": function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { var anchor = anchors;
3
33292
by: Andy | last post by:
Hello, I have the following example XML: <data> <package> <packageid>123</packageid> <package_article> <articleid>article1</articleid> </package_article> </package>
13
2376
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
1
2606
by: Max | last post by:
Hello everyone! i would want to know if the getElementsByTagName() function starts to find the elements from documentElement comprising the same documentElement. XML example: <?xml version="1.0"?> <exslt:module xmlns:exslt="http://exslt.org/documentation" xmlns="http://default-ns-outter" version="1" prefix="str" exslt:foo="bah" > ....
4
1843
by: logiczero | last post by:
Here's my code: === var content = document.getElementById('content'); var collection = content.getElementsByTagName('div'); for (var i = 0; i < collection.length; i++) { alert(collection.id); } //Replace the above loop with this one, then run again for (var i = 0; i < collection.length; i++) {
3
16563
by: windandwaves | last post by:
does it matter if I write var anchors = document.getElementsByTagName("A"); or var anchors = document.getElementsByTagName("a"); Or is there a better way to catch both <a hrefs and <A HREFS
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7613
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.