How can I handle XML namespaces in CSS Selectors or in jQuery?

前端 未结 2 1635
天涯浪人
天涯浪人 2021-01-13 04:06

I use jQuery to parse an RSS feed. I can successfully get the RSS feed using AJAX:

$.get(\"podcast.xml\", function (data) {
    xml = $(data);
}, \"xml\");
<         


        
2条回答
  •  攒了一身酷
    2021-01-13 04:15

    CSS allows you to specify namespaces for use with selectors within stylesheets.

    However, jQuery doesn't support this since you have no way of declaring the XML namespace in the first place (as jQuery has nothing to do with CSS besides borrowing from its selector syntax), so you have to treat the colon as a literal character instead by escaping it like so:

    xml.find("channel > itunes\\:image")
    

提交回复
热议问题