I'm trying to replace Xpath with jQuery

1.6k views Asked by At

Android browser not support XpathEvaluator Object.

I'm trying to replace with Xpath with JQuery.

For example,

01. oRoot.selectSingleNode("step/person"); 
->  $(oRoot).find("step person");

02. oRoot.selectSingleNode("step/person[@color='red' and age='20']"); 
->  $(oRoot).find("step person[color='red'][age=[20]");

But, I don't know how change below code?

01. oRoot.selectSingleNode("step/person[@color='red' or @color='black']");
02. oRoot.selectSingleNode("step/person[taskinfo/status='holding']");

Do you know apply OR operation to jQuery Code?

Do you konw apply one depth attribute to jQuery Code?

or Do you have other good solution?

1

There are 1 answers

0
Yëco On

There aren't conditional operators in jquery selectors, you just need to separate the selectors with a comma.

$(oRoot).find('step person[color=red] , step person[color=black]');

More on jQuery selectors http://api.jquery.com/category/selectors/

You can easily apply an attribute using jQuery's .attr():

$('step person', oRoot).attr('foo', 'bar');

More on jQuery attr: http://api.jquery.com/attr/