There doesn't seem to be any mechanism to "clear" a node of all
it's children (not that its necessary very often, but I have come
across situations where I'd like to clear a node of all it's
children before appending other nodes). I've come up with two
possibilities: Code:
I'm currently working on a pretty straight-forward AJAX application. In this application, I get some XML, and then parse it. An example of what I'm working with is as such: <?xml version="1.0"?> <postRoot xml:lang="EN"> <post type="comment" date="January 1, 1970"> <user>athlon32</user> <content>Hello World</content> </post> </postRoot>
Now, I've been able to read the XML with XMLHttpRequest , my trouble is with parsing the results. I've tried tons of things, but I just can't seem to get the different child nodes. Now, let's say we have something like this: var xml = xhr.responseXML; var allPosts = xml.getElementsByTagName('post'); Could I use childNode to access user & content? And if so, how? I've tried many things, but nothing is working :/ Is there a better way to parse the results I get back from the server?
I have two arrays. english() and french(), and each contain 10 quotes. I then have this HTML Code: <p><span class="pnum"> 1</span><span class="phrase"></span></p> <p><span class="pnum"> 2</span><span class="phrase"></span></p> <p><span class="pnum"> 3</span><span class="phrase"></span></p> <p><span class="pnum"> 4</span><span class="phrase"></span></p> <p><span class="pnum"> 5</span><span class="phrase"></span></p> <p><span class="pnum"> 6</span><span class="phrase"></span></p> <p><span class="pnum"> 7</span><span class="phrase"></span></p> <p><span class="pnum"> 8</span><span class="phrase"></span></p> <p><span class="pnum"> 9</span><span class="phrase"></span></p> <p><span class="pnum">10</span><span class="phrase"></span></p>
Look at the comment in there to see what I need to do. I assume I would use .childNodes to get the end result, but I've never worked with nodes before, how would I reference the 2nd child (aka .phrase) and loop out the array in there? Code: function eventSource(e) { var IE = document.attachEvent ? true:false; var DOM = document.addEventListener ? true: false; if (IE) return event.srcElement; else if (DOM) return e.currentTarget; } function setUpTranslation() { var phrases = document.getElementsByTagName("p"); for (var i=0; i < phrases.length; i++) { //Here I need to reference the second child and change the inner content to french[i] }}
I have been scratching my head on this one for a couple days:
Code: function hideAll(){ var education = document.getElementById("education").childNodes;
[Code]....
As far as I know, this should be working the way I expect it to (set the display of all the childnodes to none), but I guess I'm missing something. Is it not possible to instantiate a variable using childNodes without choosing a specific index of the array? I just assumed it would work like any other array
I have this code that when links are clicked the elements are erased. The issue that I am facing is that I want to update the order of the attributes "id" and "var_id". Basically when you remove the first or the second element to update the order. I am not very savvy with DOM so I have hard time developing that functionality. I hope you guys can help me with that.
<html> <head> <script> function removeElement_e(divNum) { var d = document.getElementById('e');
The problem is that I'm creating child elements based on an xml document served from a php script. However everytime it is served I'm just appending all the elements to the end of the child list creating copies. So I decided to just remove all the children each time.. But this doesn't seem to be working.
function remove_shouts(){ var shoutbox_div = document.getElementById('shouts'); var shouts = shoutbox_div.childNodes; for(var i = 0; i < shouts.length; i++){ shoutbox_div.removeChild(shouts.item(i)); } }
I'm using the following code that adds to <a> tags to each <td> inside a table. $(document).ready(function() { $('.calendar td:not(.notinmonth.)').each(function() { $(this).append('<a href="#" class="available am">AM: Available</a>').append('<a href="#" class="available pm">PM: Available</a>'); }); $('.calendar td:not(.notinmonth.)').each(function() { $(this).has('.event').remove('.am'); }); });
The second half of the code looks to see if any of the cells contain an element with class 'event'. If one exists, then the '.am' anchor should be removed. However this does not appear to be happening. After carrying out a few tests with the 'alert' function, it looks as though the script thinks that every cell contains a '.event' element, but I have no idea why! Not only that, it doesn't remove the '.am' link from any of them.
Here is the markup for the table (the cell with 'Day 9' in it is the only one that should match having an '.event' element: <table class="calendar"><thead> <tr><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th> <th class="weekend">Sat</th><th class="weekend">Sun</th></tr> </thead><tbody> <tr><td class="notinmonth"></td><td class="notinmonth"> .....
Why are anchor nodes pointing to href and text nodes pointing to [object]? As anchor and text both are objects therefore all outputs from indices 0 to 7 should be [object].
i want already select .postlike in $(this) now i want to select the tagh1 who is in .commentboxelements.i want to change the h1's inside text 1 to 2 so i write the code
$(this).closest('.posts').children('.commentboxelements center h1').html('1');
i try this but it's not worked anyway how i can do this.
so i wrote this slider with some help from an admin, everything works as I would like it to but I'm trying to make it a plugin so i need to tighten up a certain part of the code:
(function( $ ){ $.fn.jmSlider = function() { // get total width of all li elements in the slider var wrapWidth = 0;
[code]....
what i would like to do is instead of using "li:first" and "li:last", i would like to use first-child and last-child so the element doesn't need to be a li, in can be anything that is the direct child of the parent container.
I have created parent child checkboxes. When one child is selected, then parent of that child, other child of same name and parent of that same name's child will be selected... Now I want if I unchecked any child, then only same name of child and parents should be unchecked or if I unchecked Parent Child, then same name of parent and child will be unchecked.
I have a difficult work around Jquery. I want to remove all li items from the ul except first li and last three li how to remove the li elements from these list.
This pops up a new window with every call. In the child window I call a parent function onbeforeunload, appClose() :
function appClose(){
if (window.opener && !window.opener.closed){ window.opener.CloseChild(getQueryString("application")); }}
This is in my frameset tag of the child code :
<frameset ... onbeforeUnload='appClose()'>
The window.opener.CloseChild() function is called perfectly when I have one child window open, but as soon as I create another child window both of the open child windows don't ever call it. They do both go into the onbeforeunload appClose() function, but do not call the window.opener.CloseChild() function inside of this routine.
Anyone have any ideas why when I have two child windows open I can't access the window.opener functions?
I have tried taking each new window out of the array and used the following code in CloseChild() :
I'm trying to iterate through nodes in a Selection Range, but I'm having a bit of trouble determining why all nodes in the range aren't being hit. It seems like deeply nested nodes aren't being hit for some reason.
Here's the code I'm using.
var n = startNode; while (n) { this.visited.push('[' + n.nodeName + ']');
if (n == endNode) { break; }
if (n != startNode && n.hasChildNodes()) { n = n.firstChild; } else { while (!n.nextSibling) { n = n.parentNode; } n = n.nextSibling; } }
I try to associate DOM nodes with other objects. Assigning custom properties to DOM nodes works in Firefox and Safari. It also works with HTML nodes in IE6. However, it appears not to work with XML nodes that are part of trees returned by XMLHttpRequest. How can I work around this limitation? For XML nodes, I need to be able to associate at most one object with each node.
The syntax I am using is node.customproperty = value
I must be missing something very obvious, but my nightly head doesn't work anymore.
Press "Insert" button to add <insnodes after each <br>. Now press "Delete" - only even <insare being removed. ins.length is reported properly, each <inshas "insert" class name. What a...?
I'm sure I'm missing something basic, but I can't seem to find what I'm looking for. If I have an xml doc where the parent node and child nodes contain elements with the same name ("name" in this case), how would I go about just getting the client's name? Here is a slimmed down version of the structure:
function Xml_feed(file) { this.load = function() { var txt, str, title; var threads = xml.getElementsByTagName('thread'); var len = threads.length; var box = document.getElementById('box-a'); while (len-->0) { txt = document.createElement('button'); title = threads[len].getElementsByTagName('title'); str = threads[len].getElementsByTagName('author'); txt.setAttribute('label', title[0].childNodes[0].nodeValue + ' by ' + str[0].childNodes[0].nodeValue); box.appendChild(txt); } };
var xml = document.implementation.createDocument("","",null); xml.onload = this.load; try { xml.load(file); } catch (e) { alert('There was a problem loading the XML file'); } } var feed = new Xml_feed('blah.xml');
in the red:
Is that how I should be retrieving the value from a child node? (the getElementsByTagName)..
in the blue:
I tried doing this.xml but had problems with doing that, i.e, this.xml = document.implementation.createDocument("","",null); this.xml.onload = this.xml.load; try { this.xml.load(file); } catch (e) { alert('There was a problem loading the XML file'); } I'll guess that text in the red is why.. btw, this was in an XUL app.. not sure how much that would matter though..
I have a bunch of numbers on my page, wrapped in a particular HTML element e.g. <h2>5</h2>, <h2>1</h2>, <h2>3</h3>
I am looking for a javascript function that can add these numbers together. The tricky thing is that I do not know how many numbers there might be - anything from 0 to 7.
If necessary, I can give each of the <h2>'s a unique class eg. <h2 class="a">5</h2>, <h2 class="b">1</h2> etc.
I'm having trouble parsing through a table in I.E. Of course it works fine in firefox and chrome. I'm pulling html off of a txt doc and storing it in a temporary div made with createElement so I can go through and parse out the data. Code is below:
[ Code: var tempdiv = document.createElement("div"); //create temporary element to store html content in tempdiv.innerHTML = html; //dump html content into new element
[Code]....
It returns 0 for rows and and cols. If I use a getElementsById and grab a table already on the page it works fine.
And multiple other divs with similar structure, id="2", "3" etc, I want to access the <p> tags to change style-- so that, for example, the last paragraph in all of the divs would change.
To access the last paragraph, I've tried:
Code:
--which generates an error message that the function itself is undefined.
There's till something I'm not understanding about using node-seekers with classes of tags. But if I can get it right, it saves giving each of the <p> tags a class, which would be easier, but code-heavy.