/    Sign up×
Community /Pin to ProfileBookmark

using Jquery Xpath selectors to replce node data

I’m using a simple dom parser function to catch xpath information of all nodes of a document

say html is like :

[code=html]
<div>
<div>Everyday People</div>
<div>My name is ACE</div>
<div>Hello world</div>
</div>
[/code]

and parsing the DOM to store the xpath infor in array ‘arr’

[CODE]
<script type=”text/javascript” src=”js/jquery/js/jquery-1.3.2.min.js”></script>
<script type=”text/javascript” src=”js/jquery/js/xpath-selector.js”></script>

<script type=”text/javascript”>
function get_XPath(elt)
{var path = ”;
for (; elt && elt.nodeType==1; elt=elt.parentNode)
{var idx=$(elt.parentNode).children(elt.tagName).index(elt)+1;
idx>1 ? (idx='[‘+idx+’]’) : (idx=”);
path=’/’+elt.tagName.toLowerCase()+idx+path;
}
return path;
}

var arr = Array();

htmlDoc=document;
x=htmlDoc.documentElement.childNodes;

for (i=0;i<x.length;i++)
{
arr.push(get_XPath(x[i]));
}
</script>
[/CODE]

and later on in the script using the values stored in ‘arr’ to perform some functions like showing,hiding or changing content of nodes.

[CODE]
<script>
for(i=0;i<arr.length;i++)
{

//catch the object reference with the xpath info
$(arr[i])

}
</script>

[/CODE]

But in the snippet above,I’m getting a object but unable to I’m unable to get the object reference..and use it for something like

$(arr[i]).text();

any help would be greatly welcome.
Anyone worked on Jquery Xpath selectors?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @asacool spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...