Jquery Variable Claiming It's Undefined When It Has Been Defined
Solution 1:
The problem is the periods in your div's ID attributes and in your findFirmware()
function, change it to
functionfindFirmware(li) {
if( li == null ) returnalert("No match!");
firmware = li.selectFirmware;
firmwareid = phone.replace(".","");
$(".info").hide();
$('#' + phoneid + firmwareid).show(); // This line was messed up
};
There two problems with this line $(phoneid+firmware).show
, well four if you count the missing parenthesis and semicolon but...
- The div your trying to show has an ID, you don't have
#
in your selector to select the element by ID firmware
contains the unparsed string with the period sophoneid + firmware
becomesiphone2g1.2
when your div ID isiphone2g12
thus you needed to usefirmwareid
in which you parsed it out of.
Fiddle Demo: http://jsfiddle.net/AaNWM/
Solution 2:
It's probably a scoping problem. Try adding this to the top of your script:
var phone;
var phoneid;
The subsequently omit the var
phone = li.selectPhone;
Solution 3:
It's not defined anywhere that's accessible to the findFirmware()
function--it's defined as a var
in findPhone()
, hence local to that function.
Not sure what is intended by things like li.selectFirmware
etc. but those will also break.
Solution 4:
The problem is in the .
character in id.
Basically1, a name must begin with an underscore (_), a dash (-), or a letter(a–z), followed by any number of dashes, underscores, letters, or numbers. There is a catch: if the first character is a dash, the second character must2 be a letter or underscore, and the name must be at least 2 characters long.
Post a Comment for "Jquery Variable Claiming It's Undefined When It Has Been Defined"