最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin14浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论