How would I select the following in jQuery?
<ns:text value="my value" />
I have tried the snippets below, but to no avail. Is this possible?
var x= $('ns:text').attr('value');
return x;
var x= $('text').attr('value');
return x;
How would I select the following in jQuery?
<ns:text value="my value" />
I have tried the snippets below, but to no avail. Is this possible?
var x= $('ns:text').attr('value');
return x;
var x= $('text').attr('value');
return x;
You're looking for:
var x= $('ns\\:text').attr('value');
return x;
Ref:
Take a look at JQuery, XML and namespaces.
It seems that this should work:
var x = $("ns\\:text").attr("value");
Use a backslash, which itself should be escaped so JavaScript doesn't eat it:
alert($('ns\\:text').attr('value') );
(as found on this thread)
$('ns\\\:text').attr('value')
seems to be the answer but some people have mentioned some browsers may not support it... but i don't know about that as this is a jquery library unless jquery has not implemented it then maybe that could be the case:
supported and tested on: ie8, FF 3.6, chrome 3.0 i have not tested it on other browsers because i don't have them but if anyone has the answer if it works on other browsers then please add on the comment below...
$('[nodeName=ns:text]').attr('value');
Example:
$('[nodeName=geo:lat]').attr('value');
$('[nodeName=geo:lat]').val();