Since upgrading from 1.4.x to 1.6.1 all the code that selects the contents of an XML attribute by the name of 'value' has stopped working. Upon investigation, any time you do
$(someXMLObject).attr("value")
now always returns 'undefined'. This worked fine in previous versions and currently is preventing us from upgrading. I know the obvious solution would be to change the attribute name from 'value' to something else, but this would require some real effort on our part as a lot of our front end code is assuming an attribute of 'value' be passed in.
My question is, is this bug likely to be fixed in a forthcoming release of JQuery or should we implement the necessary workarounds on the assumption that this isn't being worked on?
I have a suggestion based on the assumption, which I think is correct but feel free to prove me wrong, that the .attr() method returns "undefined" in two different cases:1) when the attribute is actually not present in the dom element2) when it is present but it has no value, think for example <input type="text" disabled/> which I not is not standard HTML but I've seen it pretty often...wouldn't it be better to return undefined only in the first case, and return null in the second case? In this way, it'd be clear that the attribute is set but no value is specified.
I'm doing something with grails + jquery. My controller send a rendered json (which I know is sending correctly) but when the object "arrives" in the callback method it comes undefined. I can see it lenght, but not it's content.
I have a homework assignment which is pretty simple. It is a grade calculator that uses arrays to gather the grades from the user. This is what I have for the problematic section:
var homework = new Array(2);/* The grades entered by the user for Homework 1, 2, and 3 */ var project = new Array (3);/* The grades entered by the user for Project 1, 2, 3, and 4 */
[Code].....
My problem is the document.write portion of the code, where it is supposed to return either homework[0], project [0], or exam[0], it instead returns undefined. There is no problem with any other subscript. And yes, it does successfully prompt me for each of the [0] subscripts in the first part of the code. Am I just missing something that is right in front of my face? Does all arrays not start with the [0] subscript?
Suppose we have following javascript codes: Case 1. var foo = function (){ var x = "hello"; var bar = function () { alert(x); } return bar; } var bar_ref= foo(); document.write(bar_ref()); // it pops up "hello" and print-outs "undefined".
If we modified above code slightly, shown as follow: Case 2. var foo = function (){ var x = "hello"; var bar = function () { alert(x); } return bar(); } var bar_ref= foo(); document.write(bar_ref()); // it only pops up "hello".
As you can see, Case 2 modified the return value from "return bar" to "return bar()," which won't cause the "undefined" output. To me, it looks like when the JS interpreter executes the line "bar_ref();" it triggers the execution of function "foo", besides both "return bar" and "return bar()" do the same job which is to execute function body of "bar".
The only difference is that after the execution of function bar, its function body does not exist anymore, so when the interpreter executes the line "return bar;" it follows the function identifier "bar" and ends up with "undefined". This is why the Case 1 gives us "undefined", but I am not quite clear about why the Case 2 can trace down to the function body of "bar". Do you have any ideas about such difference outputs?
I am trying to access the width variable from my main page. Within the imageinfo.js script functions I can alert() the width value which returns 1024. But I can't seem to pass this variable to my main page or access it directly so that I can use document.write() to write the variable on the page. Whenever I try to call the 'width' variable directly from the main page I get undefined. How can I access this variable? However, with the test code below, I was able to get ducument.write() to write the 'width' variable on the page but now the page doesn't stop loading - there's an endless loop in the code...
Here is a code I use to calculate distance b//w 2 places using google api. It works perfectly and shows the results in the html but when I add a return statement at the end of the function showlocation() it returns undefined.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]"> <html xmlns="[URL]"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <meta name="robots" content="noindex,follow" /> <title>Calculate driving distance with Google Maps API</title> <script src="[URL]" type="text/javascript"></script> <!-- According to the Google Maps API Terms of Service you are required display a Google map when using the Google Maps API. see: [URL] --> <script type="text/javascript"> var geocoder, location1,addr1,addr2, location2, result1,gDir; function coolAl(add1,add2) { addr1=add1; addr2=add2; var result= return initialize(); showLocation(); alert(result); } function initialize() { geocoder = new GClientGeocoder(); gDir = new GDirections(); GEvent.addListener(gDir, "load", function() { var drivingDistanceMiles = gDir.getDistance().meters / 1609.344; var drivingDistanceKilometers = gDir.getDistance().meters / 1000; result1=location1.address + ' (' + location1.lat + ':' + location1.lon + ')/' + location2.address + ' (' + location2.lat + ':' + location2.lon + ')/' + drivingDistanceKilometers + ' kilometers'; document.body.innerHTML=result1; return drivingDistanceKilometers; }); } function showLocation() { geocoder.getLocations(addr1, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the first address"); } else { location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; geocoder.getLocations(addr2, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the second address"); } else { location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; gDir.load('from: ' + location1.address + ' to: ' + location2.address); }});}});} </script></head> <body onload="coolAl('pune','mumbai')"> </html>
This routine used to work when I was using jQuery 1.3.2. Now that I've switched to 1.4.2 it fails. I've verified that returning to 1.3.2 fixes the problem.
I have a page which includes this select pulldown:
Either I'm having a really dim Friday, or something strange is going on. I'm trying to add a method to the Validator plugin, using the following regex:
I've been using 1.3 which allows me to query non-standard attributes on tag. On an anchor I set a value="" attribute and was able to say (in an onclick binding) $(this).attr('value') to get the value. This no longer works with 1.6. Is there another, better way to do this?
I'm getting all kinds of errors, no matter where I put the parenthesis: This all works without trying to find the attr. So, I am trying to slide a ul menu that has a parent anchor with an id of "A". $(("#VerColMenu > li > a").attr('id')=='A').find("+ ul").slideToggle("slow");
I have two img tags and a jquery script which changes the value of the src attribute of each one picked from an array of images and alternatively set the display to block and assign a decreasing z-index.
The problem is that when the hidden image pops up, it seems as if, at first, set the css display to block and then change the source of the file as, for a second, it hangs to the previous loaded picture. Well I thought it was easy to manage by setting a delay but instead seems not to do anything. And then with a setTimeout but it doesn't work as expected..
I am trying to get a href attr from variable msg. The problem is that the msg consists of not only <a element but it contains also <p element and because of that attr doesn't give any value.
var msg="<p><a href='/users/'>Username</a> Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> var href=$(msg).attr('href');
how I can get the value of href from the above example?
Not really sure how the best way to start explaining this, but I have a small script set up that activates a second section to an accordion to display information. The idea is that a table cell will be clicked and then the second according will activate displaying information relating to the cell that was clicked in accordion part 1.
I have managed to get it to update coding in the var's by hand, now I want to be able to get certain bits of information from a nested div that is hidden in the table cell (I know, very messy - but it will all be made a little less messy in the future when I have got the process correct).
I've made a script to highlight an element when you rollover on another one.
// Highlight thumbnail on roll over post list item $("#sidebar-left .left-col2 a").live("hover", function(){ var title2 = $(this).attr("title"); alert("title : " + title2);
[Code]....
My problem is that the script works fine but unfortunatly just for the first li element that I rollover...
Edit: Changed dataType2 usage in 3rd line to be a regular variable and not a jQuery variable. Also, this seems to not be working in jQuery 1.5.2 either and only for Opera. I had originally thought this was working for 1.5.2 but I just re-tested and it is not. What happens is that dataType2 is undefined after the call to pull the attribute. I've also now tried .attr('[nodeName="ns1:reference"]') as well as using the same with .prop() in jQuery 1.6.1
This works in Firefox but will not in chrome. In chrome the .css works and changes the cursor to the hand on hover however .attr does not work it doesn't put the onclick attribute on any of the images.