i wrote a very simple HTML page to test some DOM features between Mozilla and IE. Mozilla is perfect everything went fine and i got the childNodes from my custom tag ( this tag i named <blah> ), inside this tag there is two <span>, that i retrieved. But with IE i really could figure out how its done! Code:
this should be simple but I cannot figure it out. This is the HTML:
HTML Code: <div id="box"> <p>one</p> <p>two <strong>three</strong></p> ... </div> The JavaScript function has to take everything inside <div id="box"> and put it into another div. It should become:
HTML Code: <div id="box"> <div class="content"> <p>one</p> <p>two <strong>three</strong></p> ... </div> </div> So how can I get all childNodes recursively to enclose them with another element?
If I use the following to get te amount of childs for xmlnames I get an amount of 11: xmlObj.responseXML.getElementsByTagName('xmlnames' )[0].childNodes.length
Is this wrong or maybe there is a better / other way of counting the child amount?
In my javascript I tried to list all the child nodes from <div>, Firefox and Opera gave me 3 -- 1)text node with a null value, 2)span, 3)text node with a null value.
It look to me that the browsers treated the line break as a text node with no value!!
If I modified the html code to : <div id="pagetitle"><span>My Text</span></div>
Then the browsers gave me the right answer: 1
They still gave me a wrong answer of 3 if I put a space around the <spanelement like this: <div id="pagetitle"<span>My Text</span</div>
What did I do wrong? I would still want the elements to be on their own lines.
I wanna get all the text nodes of the children of an element. The goal is to get an array with all the textNodes in each cell of a table, without any other nodes that might ocure whithin that cell (<p>, <br> etc...)
I mean if: <td>12</td> <td>1<p>23<b>34</b>5</p>6</td> I need: var txt = new Array() txt[0] = ཈' txt[1] = ?'
Now I had to circle through all the childNodes to extract all the text nodes. I have build a function, but something is wrong in the code, and I don't sense what. I need soime fresh eyes, any ideeas? Where's the mistake?:
<script type="text/javascript"> function checkCell(){ var allC = document.getElementById('tab').getElementsByTagName('td');//cells' collection var txt = new Array() for(var i=0;i<allC.length;i++){ txt[i]='' while(allC[i].hasChildNodes()){ var chC = allC[i].childNodes; for(var j=0;j<chC.length;j++){ if(chC[j].nodeType==3){ txt[i]+=chC[j].data; } } allC[i]=allC[i].childNodes; } } alert(txt[1]) } onload=checkCell; </script>
I have a script that automatically makes the class change for an input field onFocus. Everything works in both IE and Firefox with the inputs, but I am having trouble with an image inside of a link in Firefox. I am using a link instead of a input type="submit" for IE reasons. Code:
is there a way for me to check the child nodes of the <form> element for a specific id. in other words, can I check if form1 contains an element with id 'one' for example?
I have a javascript for a tree view but i need to change it according to the requirement. Lets start with example with the treeview as follow:
1 Door phone 1.1 Ready Kits 1.1.1 Audioset 1.1.2 Videoset
[Code]....
Now the thing is in the current treeview a single category is open at a time. like if 1.1.1 is open 1.1.2 will b closed and similarly if 1.1 is open...1.2 will b closed. But i want that when i click on 1(Door phone) ie Door phone...evry node should be opened instead of just one similary when i click on 2(CCTV), all its node should be opened.
From what I've read, everything in the DOM is a node. Basically there are three types of nodes: text, element and attribute (there are more node types but these are the most common).
Let's say I have the following html:
<html> <form> <p></p> </form </html>
Then this javascript:
var forms = document.getElementsByTagName("form") var form = forms[0]; alert(form.childNodes.length); /* output is 3 */
I would think that the output should be 2 as I only see 2 childNodes for the form object: the <p> element is an element node and the <p> element has a text node, so that's a total of 2 nodes. Where is the 3rd one comming from.
The above javascript still outputs 3. I would think that the output is 4: - 1st node is the <p> element - 2nd node is the <p> element's attribute node "title" - 3rd node is the <p> element's attribute node "id" - 4th node is the <p> element's text node
Obviously I'm not correctly comprehending how childNodes are determined.
I want to count the number of childnodes, when i run this script in mozilla i get a different total for the number of childnodes from numkids then when the script runs in IE. Why is this? How Can I get the same number. I want to loop though an objects child elements setting them to invisible or visible
<script type="text/javascript"><!-- function rec(n) {
var kids = n.childNodes; var numkids = kids.length;
Example the Region is East it has 2 cities below. I need to get this length using JS. I tried doing x=xmlDoc.getElementsByTagName("City").length; But it counts all the city elements present i.e. it returns 4. How to get the length of the "City" element particular to a "Region" element.
i'm working on a portion of a CMS that allows content-admins to browse a product list, and add individual products into the taxonomy by clicking checkboxes next to categories they might belong in.
since the taxonomy is a rather long list, i'm hiding and showing divs for the secondary and tertiary links, so when a user clicks on the checkbox for the parent category, the children appear in a second (and third) div, with checkboxes of their own.
however, i'd like for the secondary and third level checkboxes to become unchecked when the parent is. i've tried addressing them in numerous ways, but something consistently gets lost, in that i keep getting "x doesn't have any properties" errors.
ie: var parentnode = document.getElementById(divName); var allMyChildren = parentnode.childNodes.getElementsByName("INPUT"); alert(allMyChildren.length);
this returns the proper length, but then
for (var i=0;i < allMyChildren.length;i++) { var chklist = allMyChildren[i]; if (chklist.type == "checkbox") { // uncheck it } }
this consistently returns that chklist has no properties...
Is there a way to calculate the .offsetLeft or .left of a character in a string relative the element that contains the string? I'm just trying to wrap each character in an element and position the characters independently, so I have to set the .position to absolute, and set the .left and .top on each element as I create it so I can move the elements later on.
function unHide (fieldname) { .... not important... document.form1.fieldname.style.visibility = 'visible'
}
I have a field name called country in a form. When the onclick="unHide('country')" is used then the above function does not work but if i change the following line within the function document.form1.country.style.visibility = 'visible' then it works.
I've tested it in most recent versions of IE, FF, Opera, and Safari.
The first parameter is the alert's text, if a second parameter is passed, it is the alert's title, else it will just have "Alert" in the title.
You can fire the function as many times as you like, any alert's thrown after the first will set themselves on top of each other slightly staggered much like the built in alert.
The alert will automatically be placed in a visible place regardless of where the page has scrolled. They will also stay in that same place in relation to the screen if the user scrolls after the alert has fired.
The top most alert is the only one clickable and moveable until it has been acknowledged (Much like a regular alert).
The benefit of this is that it does not freeze the user's interface once the alert is thrown.
Here's the code:
Javascript:
//***************************** // Custom Alert Box // Free to use with credits in tact. // Written By Adam Matthews aka Basscyst //AdamDMatthews@Gmail.com //***************************** function msgBox(msg,hdr){ if(!document.getElementById('alerts')){ var div=document.createElement('div'); div.setAttribute('id','alerts'); document.body.appendChild(div); } var div=document.createElement('div'); div.className="alertbox"; var h3=document.createElement('h3'); h3.className="alerttitle"; var p=document.createElement('p'); p.className="alerttxt"; var footdiv=document.createElement('p'); footdiv.className="alertfoot"; div.appendChild(h3); div.appendChild(p); div.appendChild(footdiv); var but=document.createElement('input'); but.setAttribute('type','button'); but.className='alertbut' but.setAttribute('value','OK'); footdiv.appendChild(but); var hdr=(hdr) ? hdr : "Alert!"; h3.appendChild(document.createTextNode(hdr)); var cut=msg.split(" "); var len=cut.length; p.appendChild(document.createTextNode(cut[0])); for(var i=1;i<len;i++){ p.appendChild(document.createElement('br')); p.appendChild(document.createTextNode(cut[i])); } document.getElementById('alerts').appendChild(div); window.onscroll=function(){ placeAlerts(); } window.onresize=function(){ placeAlerts(); } placeAlerts(); } var posX; var posY; function mouseXY(e){ if (!e){ var e = window.event; } if (e.clientX) { posX = e.clientX + document.documentElement.scrollLeft; posY = e.clientY + document.documentElement.scrollTop; } else { posX = Math.max(e.pageX,0); posY = Math.max(e.pageY,0); } var coord=new Array(); return coord; } if(document.captureEvents){ document.captureEvents(Event.MOUSEMOVE) } function placeAlerts(){ var alerts=document.getElementById('alerts').getElementsByTagName('div'); var len=alerts.length; var x=0; var y=300; var w=document.body.clientWidth; var h=document.body.clientHeight; for(var i=0;i<len;i++){ alerts[i].style.zIndex=i+100; alerts[i].getElementsByTagName('h3')[0].onmousedown=""; alerts[i].getElementsByTagName('input')[0].onclick="";
if(window.pageYOffset){ alerts[i].style.top=y+(window.pageYOffset)+'px' }else{ alerts[i].style.top=y+(document.documentElement.scrollTop)+'px' } alerts[i].style.left=(w / 2)- (343 / 2) + x +'px'; x=x+15; y=y+15; if(i==len-1){ var h3=alerts[i].getElementsByTagName('h3')[0]; var but=alerts[i].getElementsByTagName('input')[0]; but.onclick=function(){ this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); var alerts=document.getElementById('alerts').getElementsByTagName('div'); if(alerts.length==0){ window.onscroll=""; } placeAlerts(); } h3.onmousedown=function(event){ this.parentNode.setAttribute('id','active_alert'); var event=(event)?event:arguments[0]; mouseXY(event); start_x=posX; start_left=document.getElementById('active_alert').style.left.replace('px',''); adjust=posX-start_left; document.onmousemove=function(event){ var event=(event)?event:arguments[0]; mouseXY(event); var obj=document.getElementById('active_alert'); obj.style.left=posX-adjust+'px' obj.style.top=posY-5+'px' }; } h3.onmouseup=function(){ document.onmousemove=""; this.parentNode.setAttribute('id',''); } } } }
Function Call
msgBox("You have done something real bad! So Bad, oh so bad!","Ya shoudn't of done it boy!")
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 have a custom HTML tag: <custom>text is here</custom>
I can do anything I would like in terms of calling methods with mozilla but not IE 6. For instance calling appendChild in IE results in an error. The innerHTML property is blank even though there is text between the tag.
Is there a work around for IE. What gives with IE and being able to access and manipulate custom tags??
I would like to include extra "hidden" information in a generated HTML page that can be used by javascript functions.
I realise that most browsers seem to ignore any tags and attributes they don't understand, but from what I can tell the standards do not allow me to make up my own tags or attributes as they will fail validation.
is there any standard element name that can be used for such a purpose i.e. passes validation but never produces any output (and ideally allows nested elements to be rendered normally too)...
I want to have a custom button change appearance when pressed and then call a function and change back to its original appearance when released.
here's what i have now, which works mostly. "drop" is my handler for the button, its argument tells me which button was pressed. i have a number of these buttons and they are organized in a table.
there is a fair amount of superstition here, the result of many tiny experiments i ended up with this which seems to work best: Code:
Does anyone know of a way to wrap custom tags around selected text using execCommand or otherwise?
I am developing a rich text editor for use in a web site and while there are a few decent ones already floating around I need to implement a few extra bits of functionality. Specifically tool tips. Idealy I'd like to wrap custom tags around selected text using execCommand. Ie "Selected Text" becomes:
I would like to use input type file, but i would like to put any file in it when i go on the page for example when user go back after try to submit
imagine any form to fill for send information...but after the user validate....one on the fields is bad...then the user must be correct this field.....But i don't want another fields are empty. The user must just correct one fields and keep another fields
I'm using the jquery in place editor, and I need to get the value of a custom attribute in order to send it with the form. The jquery I have is as folder... (the bit I'm having trouble with is highlighted) $(".edit").editInPlace({ url: "./server.php", params: "folder=" + $(this).attr('folder') //show_buttons: true //$('.edit').attr('folder') });
And the html is as follows: <span class="edit" folder="folderName">text to edit</span> As you can see, I need to get jquery to get the attribute 'folder' value, in this case the value returned would be 'folderName'.
I was reading about delay() in the API ref and it mentioned it used the standard effects queue or a custom queue, but didn't illustrate how you set up a custom queue.