I’m trying to do the following - document.getElementsByTagName("sup").getElementsByTagName("a");
currently I have this because I somehow need to return a combined result NodeList - // can’t prototype into NodeList because of Firefox
-
if (!Object.getElementsByTagName && Object.length)
-
{
-
Object.prototype.getElementsByTagName = function(name)
-
{
-
// the only idea I got
-
var div = document.createElement("div");
-
for (var i=0, len=this.length >>> 0; i<len; i++)
-
{
-
if (i in this)
-
{
-
div.appendChild(this[i]); // line 92
-
}
-
}
-
return div.getElementsByTagName(name);
-
}
-
}
but when running the code (FF 3.5.2) I get the following Exception:
uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER)" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: http://localhost/phileasson.xhtml#n1-1 :: anonymous :: line 92" data: no]
there are some <sup> before that, which do work. by checking the created div I found that the mentioned node has been already copied …
can anyone help me in that matter?
HTML sample code - <h4>15<sup>th</sup> – 24<sup>th</sup> Hesinde<sup><a href="#n1-3">3</a></sup></h4>
ok, now that we figured out we can’t create NodeLists by ourselves, I’ll return to the original idea of putting the relevant elements to a common (new) parent and use that to apply getElementsByTagName(). I basicly need some sort of pointers, because the original plan didn’t work as expected, I can’t use cloned nodes and moving the nodes between document and ‘parent’ is very inconvenient.
any ideas in this direction?
15 5740
I can prevent the Exception by - div.appendChild(this[i].cloneNode(true));
but that’s not returning the NodeList I need later …
Hi Dormilich,
Do u want to get the anchor object inside the <sup>? I tried out this one... -
function callJS(){
-
var subObj = document.getElementsByTagName('sup');
-
for(i=0;i<subObj.length;i++)
-
{
-
try
-
{
-
var aObj = subObj[i].getElementsByTagName('a');
-
if(aObj.length>0)
-
{
-
alert("I got the Object at the Index "+i);
-
}
-
}
-
catch(e)
-
{}
-
}
-
}
Thanks and Regards
Ramanan Kalirajan
@RamananKalirajan
yes, I want to get those anchors (which is not a problem as is), but I need them returned as one list (which is the problem here). an alert is of no use here :(
maybe it also works when returning an Array (though that’s not the same) …
Sorry, but what's the difference between "one list" and an array?
RamananKalirajan’s code doesn’t have a return value (aka one list)
getElementsByTagName() usually returns a NodeList. if I prototype getElementsByTagName into the NodeList interface I’d like it to return a NodeList too (because that’s what you’d expect). if everything fails it could also return an array…
I think the NodeList is immutable (see this article...)...
that’s also the impression I got…
I tried it...but it just wont work.
I don't think you can join NodeLists together.
Best I could do was create an array of nodes -
<html>
-
<head>
-
</head>
-
<body>
-
<input type="text" id="text1" name="text1" />
-
<input type="text" id="text2" name="text2" />
-
<input type="text" id="text3" name="text3" />
-
-
<select id="select1" name="select1">
-
<option>1</option>
-
<option>2</option>
-
</select>
-
<select id="select2" name="select2">
-
<option>1</option>
-
<option>2</option>
-
</select>
-
-
<script type="text/javascript">
-
-
var inputs = document.getElementsByTagName('input');
-
var selects = document.getElementsByTagName('select');
-
-
-
var all = new Array(inputs.length + selects.length);
-
var index = 0;
-
for (i = 0; i < inputs.length; i++)
-
all[index++] = inputs[i];
-
for (i = 0; i < selects.length; i++)
-
all[index++] = selects[i];
-
-
-
</script>
-
-
</body>
-
</html>
Sorry...maybe someone else knows more :)
I'm pretty new to JavaScript.
Haha thanks Dorm :)
I sometimes think that JavaScript is going to make my head explode. I think that over half of my problems these days has something to do with JavaScript (and the messed up idea of what Microsoft thinks Ajax should be).
@Frinavale
that’s the point, if everyone (and I mean everyone) would stick to the specs, life would be a lot easier.
@Dormilich
Sometimes it's breaking the specs that advances technology though. So even though I would love for MS to follow the rules (because it would make my life a LOT easier), I think that we would be set back a lot by enforcing the rules on everyone...
How else are we supposed to know whether or not to change the specs (in order to advance technology) unless we try the bad with the good?
ok, now that we figured out we can’t create NodeLists by ourselves, I’ll return to the original idea of putting the relevant elements to a common (new) parent and use that to apply getElementsByTagName(). I basicly need some sort of pointers, because the original plan didn’t work as expected, I can’t use cloned nodes and moving the nodes between document and ‘parent’ is very inconvenient.
any ideas in this direction?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marc |
last post by:
Hello
I have a website where I can upload a file via a form. The uploaded
file is stored in a MySQL database. When dloading te file I get a save
as... dialog box, letting me save the file. But...
|
by: Howard Jess |
last post by:
Given the html at the end of this message, I see how
a DOM NodeList exhibits its "live" behavior; that is,
adding elements to a document can change any NodeList
variables, when there's *no* code...
|
by: Øyvind Jægtnes |
last post by:
I'm playing around a bit with XPath and nodelist and i want to extract
some info from a RSS feed.
The one that i am testing at can be viewed at http://slashdot.org/index.rss
Ok.. heres the deal:...
|
by: daniel |
last post by:
Hi, Ignorant .Net Newbie Here -
I'm loading up an XML document and trying to encrypt some elements but not
others, by iterating through the nodelist returned from...
|
by: christopher.davidson |
last post by:
Hello,
I am working with XML files and utilizing Array functions to take the
XML data and combined it with some html code to display a particular
page.
The process currently works like so:
...
|
by: DP413 |
last post by:
Hey guys need your help :)
I'm trying to clone a nodelist in a bookmarklet so that I can use document.write to output each item in the nodelist to the browser.
Right now I'm basically grabbing...
|
by: carlback |
last post by:
I have a function were the input parameter can either be an
string,array,dom node or NodeList (getElementsByTagName()) and I have
somthing like this function which works great for what I want in...
|
by: sndive |
last post by:
i extract class object from an instance of NodeList (minicompat.py)
like so
PyObject *pclass = PyObject_GetAttrString( nodelistinsance,
"__class__");
but
PyObject_GetAttrString(pclass,...
|
by: ranjitha55 |
last post by:
but it is displaying al values der in xml file.it should avoid reading duplicate values ,pls help me..
my code is,
public class nm {
public static void main(String argv) {
try {
File...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |