I have an XML :
<computers>
<computer>
<description>Description</description>
<computer.always></computer.always>
</computer>
</computers>
So i want to access the computer.always element, so I use this :
$(xml).find('computer ' + "computer.always".replace(/\./g,'\\\\.'))
And the element is not found.
( I wrote “computer.always”.replace(/./g,’\\.’) because “computer.always” can be a variable and i need to make this selector dynamic. )
The weird thing is :
When I do :
$(xml).find('computer computer\\.always') // Element found
My element is find.
But when I use the result of “computer.always”.replace(/./g,’\\.’), it fails.
"computer.always".replace(/\./g,'\\\\.') // return "computer computer\\.always" in the console
$(xml).find("computer.always".replace(/\./g,'\\\\.')) => []
Anyone can help me?
In fact, my error was to use double \, so the console use it to echo but not my code. My solution was to use :