bore icon indicating copy to clipboard operation
bore copied to clipboard

Support HTML in querying functions

Open treshugart opened this issue 8 years ago • 0 comments

Currently we support HTML in mount() but it'd be nice if this was also supported in all() et al to match that. For example:

mount('<div><span></span></div>').one('<span></span>');

If we do this, the heuristic for seeing if it's a selector or HTML needs to be considered. Upon initial inspection, it seems that you can do something like:

// This would match HTML
query.trim().indexOf('<') === 0

The only downsides, which we can't do anything about other than trimming around the string is whitespace inside of the node, which has to match exactly. This can catch you up if you use template literals:

// Matches because trim()
mount('<div><span></span></div>').one(`
  <span></span>
`);

// Does not match because inner whitespace.
// JSX works because it ignores whitespace.
mount('<div><span></span></div>').one(`
  <span>
  </span>
`);

This would probably just need to be emphasised in the docs when documenting this form of the arguments.

treshugart avatar Nov 25 '16 00:11 treshugart