views:

73

answers:

5

how would i select the following in jquery <ns:text value="my value" />

i have tried selecting it like so: 1:

var x= $('ns:text').attr('value'); 
return x;

2:

var x= $('text').attr('value'); 
return x;

but nothing so far... i don't know if it is possible or not but ...

Thanks

+1  A: 

Take a look at JQuery, XML and namespaces.

It seems that this should work:

var x = $("ns\\:text").attr("value");
cletus
oops you posted it before while i was typing the answer but got my vote lol :)
Val
A: 

Use a backslash, which itself should be escaped so JavaScript doesn't eat it:

   alert($('ns\\:text').attr('value') );

(as found on this thread)

pixeline
Thanks worth reading it.
Val
A: 
$('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...

Val
2 slashes, not 3.
pixeline
+2  A: 

You're looking for:

var x= $('ns\\:text').attr('value'); 
return x;

Ref:

K Prime
what is the difference between two escapes and three escapes?
Val
with 3 escapes, jquery will look for ns\:text instead of ns:text
pixeline
both work... so i would of thought they both are correct right?
Val
It happens that 3 slashes works, because `\:` has no special meaning. By contrast, `'\\n'` would be a 2-char string, while `'\\\n'` would be the newline char
K Prime
A: 

Works in webkit and alle the other Browsers too


$('[nodeName=ns:text]').attr('value');

Example:

$('[nodeName=geo:lat]').attr('value');
$('[nodeName=geo:lat]').val();
simon