-3

Html

<div id="slideit">
 <a href="javaScript:void(0)">google</a>
</div>
<div>
 <p>Test</p>
</div>
<div>
 <p>Test</p>
</div>

Right now I am working on project where some one insist to use xPath selector.

I have similar DOM structure as i mention above. I want change color of second div.

  • How to use xpath selector in jQuery
BoyKha
  • 27
  • 1
  • 5

1 Answers1

1

This might help you.

stackoverflow link

function _x(STR_XPATH) {
            var xresult = document.evaluate(STR_XPATH, document, null, XPathResult.ANY_TYPE, null);
            var xnodes = [];
            var xres;
            while (xres = xresult.iterateNext()) {
                xnodes.push(xres);
            }

            return xnodes;
        }
        $(_x('//div[@id="slideit"]/a[contains(@href, "javaScript:void(0)")]/..//following-sibling::div[1]')).css({
            'color': 'red'
        });
Community
  • 1
  • 1
Shirish Patel
  • 874
  • 6
  • 14