javascript - toString method in jquery? or something similar - Stack Overflow

ANSWER FOUND!I'm reading an xml document and I am sending this to a function$(data).find('col

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
Add a ment  | 

2 Answers 2

Reset to default 3

The 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744198096a4562751.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信