Skip to content

Instantly share code, notes, and snippets.

@pj
Created February 24, 2016 08:44
Show Gist options
  • Save pj/c375f2f8ddd8d5991be8 to your computer and use it in GitHub Desktop.
Save pj/c375f2f8ddd8d5991be8 to your computer and use it in GitHub Desktop.
node js x-ray accessing selected element properties
var html = `<html>
<body>
<div id="someId">
<a href="http://example.com/page1">Page 1</a>
<a href="http://example.com/page2">Page 2</a>
</div>
</body>
</html>`;
// If you have html like the above and you want to access properties of the links that
// are children of the div you need to do the following. The blank string in the bar
// property selects the links text.
x(html, '#someId a', [{foo: '@href', bar: ''}])(function(err, obj) {
console.log(obj);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment