I'm trying to get the value of an object's property. getAttribute returns "null" even though I'm sure the property is set. I can easily set the property, and in my actual script I do so dynamically. I just want to read the property and can't.
To help explain my problem, I've attached an example .html file as a .txt file.
The critical part of the code is this section that is based on "textbook" examples of how to get an attribute:
<script type="text/javascript"> function showcolor() { var myobject = document.getElementById("lab"); var myproperty = myobject.getAttribute("color");
alert(myproperty); } </script>
This is called via a button on the bottom of the page. The DIV object with the ID "lab" exists and has a color attribute defined in CSS, but I cannot read it, nor any other attribute, with a script. The alert displays "null".
I am trying to get my script working in FF, IE and Opera but the getAttribute isn't working for me. The domain name isn't getting picked up I have tried this:
In the doucmentation I'm reading that images in the same gallery need to have the same rel attribute value. But when I do that only the loading animated gif will show on top of the overlay. If I take out the rel then each image will display in a single thickbox. How can I get a gallery of images to display in the thickbox?
I have following HTML code: <br/> <div style="display:none">.....</div> <div style="display:none">.....</div> How can I modify display to block in style attribute with Javascript?
It seems to be a problem with the getAttribute('style') portion of the code because if I change the request to getAttribute('id') it executes properly....
During development of Bing Maps, I've come across a problem when reading in an XML file and plotting a ploygon. The code works fine on IE, but FireFox is giving me the following error message: Error: xNodes[i].getAttribute is not a function
The function in its entirety is copied below and the problem line is marked in red. Hoping that someone may have come across this problem?
I am trying to get a url attribute from an xml node: <item> <media url="http://blablabla.com" /> </item>
I can do this in IE with the following code: var newDom = xmlhttp.responseXML; var x = newDom.getElementsByTagName("item"); var urlNode = x[0].getElementsByTagName('media'); var myUrl = urlNode[0].getAttribute('url');
If I try this code in FireFox it gives me the following error:
urlNode[0] has no properties referring to this line : myUrl = urlNode[0].getAttribute('url');
i have found a possible bug in 1.4 but it's only in Internet Explorer 7 & 8.The following code does not work and completely ruins every peice of jquery on the page (that means everything inside $(document).ready and anyting else...
I cant see any syntax errors - i pulled the example from the 1.4 site. There is no trailing commas in the object notation and i really cant see any reason it would work in firefox and not IEx and more to the point not only not work in IEx but break any other jquery in the entire page....
I'm working with a large (and unweildy) ASP.NET application, and there is a lot of jQuery code that uses selectors like this:
[name=_aspnetControl$_withASubControl] And unfortunately, some selectors that also look like this:
[name^=_someAspNetControl$_radioButtonList].
In other words, the effort to remove the $ from the attribute selectors would be monumental. If it is possible to escape the $ symbols, I can do that easily enough, but unfortunately the situation right now means that I can't upgrade to jQuery 1.5.
I'm learning jQuery with XML. I'm familiar with other query languages such as XPath. I'm having a little bit of difficulty wrapping my brain around how jQuery works but I think I can make the leap if I see a solution to a problem I know how to solve with other methods Given the following XML, please share a jQuery solution to finding the value of attribute B in elements named bar where attribute A has the value 30:
I'll trying to tell the difference between the following three cases:
<img alt="text string" /> <img alt="" /> <img />
I can do this in Firefox with the following code, where elem is the HTMLElement representing each image, but IE doesn't seem to differentiate between empty string and undefined.
var alt = elem.getAttribute('alt'); alt = (alt) ? alt : ((alt===null) ? 'really_null' : "");
The desired output from running this code on the 3 tags above is:
text string
really_null
It seems like this should be really easy...but I'm having a really difficult time trying to figure out what's going on...
I'm working on a slider script and it would be just lovely to be able to specify the slider's width in a width attribute on the input that represents it. In the code below, getAttribute("width") is returning 0 in IE, but seems to work fine in firefox. . . .
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script type="text/javascript"> var curr_slide=""; var ie = (document.all && !window.opera)?1:0; if (!ie) document.captureEvents(Event.MOUSEMOVE) var tempX = 0 var tempY = 0 var slide_width=200; window.onload=function() { buildSlider(); } function buildSlider() { var sliders=getElementsByClassName(document,'input','slider'); var len=sliders.length; for(var i=0;i<len;i++) { var div=document.createElement('div'); div.className='slider_house' alert(sliders[i].getAttribute('width')); if(sliders[i].getAttribute('width')) { slide_width=sliders[i].getAttribute('width')*1; } div.style.width=(slide_width+10)*1+'px' var handle=document.createElement('div'); handle.className='handle' handle.style.left=Ɔpx' handle.onmousedown=function() { curr_slide=this; document.onmousemove=function(e) { getMouseXY(e); } document.onmouseup=function() { document.onmousemove=""; } } div.appendChild(handle); sliders[i].parentNode.insertBefore(div,sliders[i]); } } function getSlide(obj) { var s=obj.parentNode; var lft1=s.offsetLeft; var lft2=obj.offsetLeft; var num=(lft2-lft1)-1; if(ie) { num=num-10; } return num; } function getElementsByClassName(oElm, strTagName, strClassName){ var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); strClassName = strClassName.replace(/-/g, "-"); var oRegExp = new RegExp("(^|s)" + strClassName + "(s|$)"); var oElement; for(var i=0; i<arrElements.length; i++){ oElement = arrElements[i]; if(oRegExp.test(oElement.className)){ arrReturnElements.push(oElement); } } return (arrReturnElements) } function getMouseXY(e) { if (ie) { tempX = event.clientX + document.body.scrollLeft tempY = event.clientY + document.body.scrollTop } else { tempX = e.pageX tempY = e.pageY } if(tempX < 0) { tempX = 0 } if(tempY < 0) { tempY = 0 } n_spot=tempX-curr_slide.parentNode.offsetLeft; var c_obj=curr_slide.parentNode.nextSibling;
As you might know, removeNode() is an IE DOM extension (works only for IE5, IE6 and Opera 8 but not in IE 5.2 for Mac, Moz, Safari.
Following one of my clients request I think I found a cross-browser solution to remove a node but keeping it's childs. The request was to find a function which will remove, onevent, the <a href=""> tags, but keeping the inner text.
This is what I have done. If you know a better or a shorter solution, please let me know:
function removeN(tag){ var tags = document.getElementsByTagName(tag); for (var i=tags.length-1;i>=0;i--){ var root = tags[i].parentNode; var kids = tags[i].childNodes; var eSpan = document.createElement('span') for(var j=0;j<kids.length;j++){ clon = kids[j].cloneNode(true); eSpan.appendChild(clon) } root.replaceChild(eSpan,tags[i]) } }
the variable tag might be 'a', 'strong', 'em'....
I guess that the code might be used as a crossbrowser solution for replaceNode() as well. In fact the code as it is replaces the node tag with a <span> tag, but it might replace it whith another desired tag....
We have to develop a small engine which the client uses. It supposed to work like this. Our engine resides in a frame (frameA) which will be loaded only once and it provides set of functions. The client can call these functions. We inturn should get the values from the server or set the values in the server and return with the values. The way we are planning to implement is that we will have have another frame (frameB hidden) and submit it whenever the client (frameClient) calls our function and wait till the page reloads and return with the value ( set in the reloaded page by the server). The problem we face now is that we don't have any sleep functionality in javascript ( being event driven) and if we have a loop waiting for the reply, it will consume the cpu cycles and the the frameB wont load.
Posting this in javascript because the problem might be caused by my scripting.
I made a 3 page long form using javascript, and the contents of the second page aren't submitted to the php script. link (http://rolstoel.dlnet.org/toevoegen.php?page=1)
I am working on this simple calculator that passes values from one function to another via paramters. I have used alert() to find what is being recieved, so far nothing. code...
I'm making a php/html page and using javascript to keep a count for me. code... The last button is just a test button, which will tell me what the value of "i" is, but I'm not getting anything when I cllick that button.
However if I change the onClick from alert(i), to alert('i') it will alert me a string, so I know the javascript is working.
I am trying to fix some datetime strings so I can convert form values into date objects so I can compare the dates in my validation process. the date time strings look like - 7/21/2011 8:00am
for some reason the am is not being replaced by " am" . here's the function code...
If the new window is "killed" because of the software, it loads a new page in the parent window ... or the last line of code can be replaced with a document.write('content here'); or show a hidden <div>. Any of these three can be used to tell the user to disable the software).
It works on my computer with ie6 ... let me know how it works on yours (if you have popup killer software installed).
I have been looking around for quite some time for a simple piece of code that allows rows to be collapsed in tables, so when you click on a link in the tbale the row beneath collapses. All i have found are very complex codes that i cant get to work or that dont work in both IE and FF.
I have a javascript running on my site at that disables right clicking (viewing source, saving pictures, etc.) that works beautifully in IE...but not in Firefox. Does anyone know of a solution?