Dormilich 8,658
Recognized Expert Moderator Expert
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_INVAL ID_POINTER)" nsresult: "0x80004003 (NS_ERROR_INVAL ID_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>
15 5764 Dormilich 8,658
Recognized Expert Moderator Expert
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
Dormilich 8,658
Recognized Expert Moderator Expert @RamananKaliraja n
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) …
Frinavale 9,735
Recognized Expert Moderator Expert
Sorry, but what's the difference between "one list" and an array?
Dormilich 8,658
Recognized Expert Moderator Expert
RamananKaliraja n’s code doesn’t have a return value (aka one list)
getElementsByTa gName() usually returns a NodeList. if I prototype getElementsByTa gName 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…
Frinavale 9,735
Recognized Expert Moderator Expert
I think the NodeList is immutable (see this article...)...
Dormilich 8,658
Recognized Expert Moderator Expert
that’s also the impression I got…
Frinavale 9,735
Recognized Expert Moderator Expert
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.
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 when it is dloaded and
I open it, it contains te HTML code of the file displayed...
Wordt thin g is - it _used_ to work so the code is OK - only some
little thing changed. Maybe the header part???
Thanks.
|
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 that refers to them.
I suppose I can imagine cases where this idea would be
useful, but I can imagine many more where I'd like to
get a *static* list of, e.g., the <p> elements in my
document, and do something with them, regardless of any
I...
|
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:
I load xml via httpwebrequest etc and put it in a XmlDocument.
xmlFeed.Load(xRes.GetResponseStream());
This works fine as i can use this stream with a XmlReader to parse the
|
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
XmlDocument.GetElementsByName(). Goofy things happen. I get back 8
elements, but as I step through the nodes, encrypting and calling
EncryptedXml.ReplaseData(), I end up with several of the elements turning
into null.
I started by treating the nodelist as an array, and...
|
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:
1.) Request an Async request of the XML
2.) Once complete, parse the appropriate XML data to parse
| |
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 a nodelist, iterating through it and getting stopped after the first document.write, which I think is because the nodelist reference disappears after the document is changed with document.write.
javascript: var someElements =...
|
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 every
case except if the pNd is the NodeList at which point I end up with the
nodeList in the first element of the array instead of acting like the
array would.
function doSomething(pNd){
if(pNd.constructor != Array){pNd = new Array(pNd)}...
|
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, "__len__")
returns NULL.
i naively added
__len__ = _get_length
|
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 file = new File("c://adv.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |