开发者

Finding an attribute in an XML file using jQuery

开发者 https://www.devze.com 2023-03-20 09:23 出处:网络
I have this XML file, and I would like to find the lektion_lexi_margin value. The only th开发者_StackOverflow中文版ing known about the value is the attribute thessi. How can I accomplish that?

I have this XML file, and I would like to find the lektion_lexi_margin value. The only th开发者_StackOverflow中文版ing known about the value is the attribute thessi. How can I accomplish that?

I tried the following code without success

margin_left = $("[thessi$="+Pc+"]").attr("lektion_lexi_margin");

<?xml version="1.0" encoding="UTF-8"?>
<lektionen>
    <Lektion>
        <lektion></lektion>
        <lektion_buch>Arbeitsbuch</lektion_buch>
        <lektion_frage_text_ap view="" typ="" thessi=""></lektion_frage_text_ap>
        <lektion_photo thessi=""></lektion_photo>
        <lektion_teil></lektion_teil>
        <lektion_title></lektion_title>
        <lektion_bearbeitung>
            <lektion_ap thessi="1" lektion_lexi_margin="7">was</lektion_ap>
            <lektion_ap thessi="3" lektion_lexi_margin="10">das</lektion_ap>
        </lektion_bearbeitung>
    </Lektion>
</lektionen>


You can do this:

$.each($(xml).find('lektion_ap'),function(){
    alert($(this).attr('lektion_lexi_margin'));
});

http://jsfiddle.net/lfrias/YgVA5/


Try this

$('xml lektion_ap').each(function(){
    alert($(this).attr('lektion_lexi_margin'));
});
0

精彩评论

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