开发者

toString method in jquery? or something similar

ANSWER FOUND!开发者_如何学Python

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?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜