I am trying to get the value of an attribute of an XML node and set it as a variable using JQuery. Is this possible?
<DataContainer>
<Customers>
<Customer customerId="7366" customerName="Boardwalk Audi" url=""
address="5930 West Plano Pkwy" city="Plano" state="Texas"
zipCode="75093" latitude="33.0160690000000000"
longitude="-96.8268970000000000">
<Customers>
<DataContainer>
I want to set the customerId attribute of 7366 as a variable for later use like below:
$customerId = customer id from xml node attribute;
Is this possible? Let me know if you need any more clarification. Thanks!
If you’re fetching the XML in an ajax request you can just use
.find()to get the node and.attr()to get the attriute, for example:You can see an example here, keep in mind this is intended to be used in an ajax callback ultimately using
responseXML(not just an XML string), but you get the idea 🙂