I tring to get the attribute value from the following simple xml using my javascript.
XML :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ParentNode Symbol="$"><Row book = "test" price ="80"/></ParentNode>
jQuery: $('ParentNode').attr('Symbol');
The JQuery is working fine if the xml code is
<ParentNode Symbol="$"><Row book = "test" price ="80"/> </ParentNode>
The attr() method sets or returns attributes and values of the selected elements. When this method is used to return the attribute value, it returns the value of the FIRST matched element.
Get the Value of an Attribute Unlike element nodes, attribute nodes have text values. The way to get the value of an attribute, is to get its text value. This can be done using the getAttribute() method or using the nodeValue property of the attribute node.
Try
var string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ParentNode Symbol="$"><Row book = "test" price ="80"/></ParentNode>';
var $doc = $.parseXML(string);
console.log($($doc).find('ParentNode').attr('Symbol'))
Demo: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With