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
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 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');
i have a menu generated by a list with nested lists. i want the parent link to stay highlighted when the mouse hovers over the sub menus. because those sub menus are also generated by jquery (qtip), CSS alone won't do it (triedul.topnav li:hover a {background-color: #F00;}).is there a way to do this using jquery?
The bit of code in bold in the code below is giving me this error in IE: Error: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; Tablet PC 2.0; InfoPath.2; OfficeLiveConnector.1.4; .NET CLR 3.0.30729; OfficeLivePatch.1.3; MSN OptimizedIE8;ENGB)Timestamp: Tue, 16 Mar 2010 15:07:11 UTC Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
I have a javascript here for adding my div element to my registration form,Adding the div element is easy, but it shows on the bottom of my form. I cant make it as the first child element of my form...This is my code
var _form = document.getElementById('registration_form'); var errorDiv = document.createElement('div'); errorDiv.setAttribute('class', 'confBox');
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].
In a project repeated blocks are identified by an <input type="hidden" value="x" /> field. To get an access to one of the block I wanted first access to that field. My first problem is there and I will explain it by a micro-project (tested with Firefox only)
Here is the HTML code : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href = "index.css" type="text/css" /> <script type="text/javascript" src='Library/jquery-1.4.js'></script> <script type="text/javascript" src='index.js'></script> .....
And here the javascript code wher is the JQuery question //meta http-equiv content-type charset=utf8 function test(){ var $id = $('#curUnion').val(); var $objet = $('#toutesUnions > .pseudoFieldset').find('input[value=$id]'); var $test = $objet.val(); var $objet2 = $('#toutesUnions > .pseudoFieldset').find('input[value="1"]'); .....
With $id = "1" as shown by the Javascript debugger (in Firefox) where is the difference between find('input[value=$id]') and find('input[value="1"]') Giving the alert result => undefined / 1 If you want to test the micro project you will find it in the Test.zip joined. How to access the immediate parent pseudoFieldset to get its html code?
I am trying to access an element in a page using ID using jquery in when the document is ready.But the problem is the length is always 0 even if the script tag is in the head or right at the bottom of the page. The element is seen rendered when I see it using FireBug.an someone point out where I am making a mistake accessing the element
i am creating text box Elements using DOM if only user needs it by using Create Element
var element = document.createElement("input"); element.setAttribute("type", "Textbox"); element.setAttribute("name", "group[]"); newdiv.appendChild(element);
How do I get the contents of an element in the opener and show them in the child?
What I'm trying to do is something like this:
In the opener: <h1 id="pgtitle">Office XP</h1>
In the child: function gt_pageCont () { var pagetitle = window.opener.document.getElementById("pgtitle"); var pagetext = "<h1>""+title+""</h1><p>Here are some more info about "" +title+ "".</p>"; document.write(pagetext); }
and: <body onload="gt_pageCont();">
I know that something is missing in the function, because I've tested it and the child displays [Object] instead of "Office XP".
I've got a reference to a TableCell and I'd like to use jQuery to get the first instance of an <IMG> tag within that TableCell, but can't get the syntax right, I understand how it would work if I were to reference the TableCell by and ID or class, but not when I have a direct reference to the cell, I've got:
What the jQuery syntax should be to get the first img tag within "tdRef"?
I have a function which looks like function mainLeftElements(){ var containerDiv = document.getElementById('mainLeft'); var elems = containerDiv.childNodes; alert(elems.length); }
Which for a div declared like so: <div id = 'mainLeft'></div> Alerts me it has a length of 1, trying to work out what the element is (thinking it might be a blank text element or something, maybe the id attribute also??) by using elems[0].tagName and elems[0].id I get confused as they both return 'undefined', so what is it?
alerts me it has a length of 1, trying to work out what the element is (thinking it might be a blank text element or something, maybe the id attribute also??) by using
and
i get confused as they both return 'undefined', so what is it?
I need a way to select BOTH the first occurrence of <div class='posts'></div> and the LAST occurrence of <div class='posts'></div>. Then I need to set different css rules for both of them. In CSS, I can use first-child, but this doesn't work in older browsers. CSS last-child does not work here because it targets date_area and also doesn't work in older browsers.
Assuming the name of my form was "form", I could access the value of the text fields by "window.document.form.FIELDNAME.value" and the select by "window.document.form.public.selectedIndex". But the page i'm working with has multiple products listed and so I've addopted a nming convention for the elements name's so that I could access it more efficiently in PHP. So for example, I'd have multiple products as such Code:
and i want to access the element dropSubPrd that is inserted on that ajax function, on the div FirstResult, but it will not work in $('document').ready because when the page load's that element isnt there.
I have 1 form, and dozens of elements. In the select elements I use onchange="somefunc()". In this function I'd like to access and change the form element attributes (such as form.element.option[].value and form.element.option[].innerHTML).
Is there a way to access the element that has just changed (unsing onchange="somefunc()") by passing a "this.element" parameter to access the elements properties such as form.element.option[].value within the function?
I am dynamically building a part of my HTML page by setting the innerHTML of a DIV element. Immediately after I do that I try to retrieve the clientHeight and clientWidth of the DIV element in order to determine what height and width the element actually ended up being. But I always get 0 as both the height and width. The contents of the DIV, i.e. the HTML code that I inserted into it via the innerHTML, does indeed get displayed on the page. But I suspect that the browser doesn't actually update the page until AFTER my JavaScript code has completed and "returns control" to the browser.
Does that make sense? Is there any way I can force the browser to update the page BEFORE my code completes its processing, so that I can properly retrieve the width and height of the element I just inserted into the page?
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"> .....