开发者

jquery 'find' cant find gx:Track

My problem is Jquery find function.

this is my kml code ~

.
..
...
<Placemark>
    <name>Happy Dinner 2011-05-21 16:57</name>
    <styleUrl>#msn_track-0</styleUrl>
    <gx:Track>
        <when>2011-05-21T07:57:44Z</when>
        <when>2011-05-21T07:58:29Z</when>
  开发者_开发知识库      <when>2011-05-21T07:59:12Z</when>
        <when>2011-05-21T07:59:41Z</when>
        <when>2011-05-21T07:59:53Z</when>
        <when>2011-05-21T08:00:29Z</when>
        ...
        <gx:coord>127.03971 37.51795 99.59999999999999</gx:coord>
        <gx:coord>127.03998 37.51816 101.8</gx:coord>
        <gx:coord>127.03958 37.51816 106.8</gx:coord>
        ..
        .

as you know I can access dom using find,

//data is the xml(kml) file loaded.
$(data).find('Placemark')

this works correctly, return object array.

but,

$(data).find('gx:Track')

this doesn't work, return empty jquery object.

$(data).find('gx:coord')

also doesn't work.

anyone who know the reason and solution?


My suspicion is that it see's the :track part of the string as a jQuery pseudo-selector (like :first-child etc).

You can escape the : by putting a \\ before it, so your selector would become:

$(data).find('gx\\:Track')

http://api.jquery.com/category/selectors/ for the explanation of controlled selector characters.


escape the : with \\

Like this:

$(data).find('gx\\:Track')


I believe that jQuery selectors do not recognize XML namespaces.

You can try this: $(data).find('gx\:coord') but something tells me it will not work either.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜