Suppose I have some XML received from an AJAX call. I know how to use selectors on the web page, e.g. if I had <p id="foo"></p> then $("#foo") would select it, but is there a way to get that selector to target my XML instead? So if my XML contained <foo bar="baz"></foo>, then I could select it with $("[bar='baz']").
Suppose I have some XML received from an AJAX call. I know how to
Share
Yes, you can; you just need to pass that XMLDocument into jQuery selector (as its
contextparameter). In fact, you can happily pass a string there:Note that it’s (obviously) quite a weird idea to use it like this:
… as jQuery will have to reparse that xml string into the XMLDocument object each time.