0

I'm want to get the value of an attribute using JQuery. This is a part of my XML:

<VertrekkendeTrein>
    <RitNummer>1583</RitNummer>
    <VertrekTijd>2014-09-09T21:24:00+0200</VertrekTijd>


    <EindBestemming>Amersfoort</EindBestemming>
    <TreinSoort>Intercity</TreinSoort>

        <RouteTekst>Hoorn, A'dam Sloterdijk, Amsterdam C.</RouteTekst>

        <Vervoerder>NS</Vervoerder>

    <VertrekSpoor wijziging="false">1</VertrekSpoor>

        <ReisTip>Stopt tot Hoorn op tussengelegen stations</ReisTip>

</VertrekkendeTrein>

I want to know if wijziging is "true" of "false". I tried this using JQuery:

var tijden = $(response).find("VertrekSpoor").attr("wijziging");

for (var i = 0; i < tijden.length; i++) {
    if (tijden === "true") {
        $(".spoor").css({'color':'rgba(255,0,4,1.00)'});    
    }   
}

Hopefully someone can help me with this. I know there are more questions about this problem, but I couldn't find one that fixed my problem.

1 Answer 1

1

you are doing it right. I think either your XML is breaking because of Quotation marks "" or before writing your find method you have not parsed it.
Just tried with your script and it is working. Hope this will help you :)

           <script type="text/javascript">
        $(document).ready(function () {
            var yourxml = "<VertrekkendeTrein><RitNummer>1583</RitNummer><VertrekTijd>2014-09-09T21:24:00+0200</VertrekTijd>" +
                        "<EindBestemming>Amersfoort</EindBestemming><TreinSoort>Intercity</TreinSoort><RouteTekst>" +
                        "Hoorn, A'dam Sloterdijk, Amsterdam C.</RouteTekst><Vervoerder>NS</Vervoerder><VertrekSpoor wijziging='false'>1" +
                    "</VertrekSpoor><ReisTip>Stopt tot Hoorn op tussengelegen stations</ReisTip></VertrekkendeTrein>";
            xmlDoc = $.parseXML(yourxml);
            $xml = $(xmlDoc);
            tijden = $xml.find("VertrekSpoor").attr("wijziging");
            if (tijden === "true") {
                $(".spoor").css({ 'color': 'rgba(255,0,4,1.00)' });
            }
        });
    </script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.