473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Cloning a Nodelist in a Bookmarklet

1
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.


[PHP]javascript: var someElements = document.getElementsByTagName('a'); function writeElements(theElements){for(i = 0; i < theElements.length; i++){ document.write(theElements[i].href);}}; writeElements(someElements ); [/PHP]

In non booklet form:
[PHP]var someElements = document.getElementsByTagName('a');
function writeElements(theElements){
for(i = 0; i < theElements.length; i++){
document.write(theElements[i].href);
}
};
writeElements(someElements); [/PHP]
That bookmarklet will print out the first link then fail because theElement = nothing when the new page is written.

I'd really like to know how you can create a hard, deep, complete copy of an array of objects (I think that's what a nodelist is) so that I can write all of a pages links to the browser.

If there is any need for clarificaiton please let me know, thank you.
Sep 9 '06 #1
1 1987
acoder
16,027 Expert Mod 8TB
For a node, you can create a complete deep copy using cloneNode(true) - see link.

Instead of document.write(), use DOM methods such as document.createElement(), createTextNode(), appendChild(), etc. or even innerHTML.
May 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
2
by: Gaikokujin Kyofusho | last post by:
Hi, I am trying to find a wikipedia bookmarklet for Opera that would allow me to lookup something highlighted on a page. I could have sworn that the one i had worked until i had to reinstall opera...
1
by: Robert Oschler | last post by:
In pre-Windows XP Internet Explorer, adding a bookmarklet for a user was really simple. All I add to do was create a link that executed addFavorite(). Internet Explorer under Windows XP won't...
4
by: gwtc | last post by:
Here is a google search site bookmarklet. This lets you search a certain website using google. What I want is the same thing, but to search a certain geocities site. When you use the current...
25
by: bweaverusenet | last post by:
Hi. I am trying to get some javascript to work in IE6, from the address line. It works in Firefox and, I believe, IE7. It appears that with some number of nested structures, the code does not...
7
by: Amir Michail | last post by:
Hi, I would like to add a submission bookmarklet to my app that takes the current selection and pastes it into the app's rich text editor while preserving formatting. It should work in at least...
2
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,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.