ANSWER FOUND!
I'm reading an xml document and I am sending this to a function
$(data).find('colleges').attr('next')
that returns discipline
and javascript is thinking it's a variable, can I some how get the attribute in the tag and have it return as a string like 'discipline'
Is there a toString()-type method that I could add onto the selection?
$(data).find('colleges').attr('next').toString()
The issue I am having is that I am sending that to a function
createSelect( $(data).find('colleges').attr('next') )
but firebug is giving me an error saying that the value, discipline, is undefined? Why is javascript reading discipline as a var and not a string?
ANSWER FOUND!
I'm reading an xml document and I am sending this to a function
$(data).find('colleges').attr('next')
that returns discipline
and javascript is thinking it's a variable, can I some how get the attribute in the tag and have it return as a string like 'discipline'
Is there a toString()-type method that I could add onto the selection?
$(data).find('colleges').attr('next').toString()
The issue I am having is that I am sending that to a function
createSelect( $(data).find('colleges').attr('next') )
but firebug is giving me an error saying that the value, discipline, is undefined? Why is javascript reading discipline as a var and not a string?
Share Improve this question edited Feb 18, 2011 at 4:09 Phil asked Feb 18, 2011 at 3:36 PhilPhil 11.2k17 gold badges72 silver badges105 bronze badges 3- 6 Your question makes no sense. You need to learn the fundamentals of variables and values. – SLaks Commented Feb 18, 2011 at 3:38
- i think he wants the tag name as as string? hard to tell – Darko Commented Feb 18, 2011 at 3:45
-
1
Please post the value referenced by
data
so we can better see what you're after. – user113716 Commented Feb 18, 2011 at 3:48
2 Answers
Reset to default 3The attr
function returns a string, which you can put into a variable.
If this...
$(data).find('colleges')
...doesn't find any matches ( <colleges>...</colleges>
), then this...
.attr('next')
...will return undefined
.
The first thing you should do is test to see if the .find()
found anything.
alert( $(data).find('colleges').length );
If the alert
gives you 0
, then there were no matches, and you'll have to inspect your data
to see if it contains what you expect.