(document.evaluate) & # 8594; src image contains several conditions, how?

please don't hit me with hate. I am noob. hiding in the corner

I am new to Greasemonkey and its syntax, so your help is much appreciated!

I am trying to extract multiple images based on the words contained in their src url, but I cannot understand the correct syntax for several conditions if src is not a complete match.

var snapImages =document.evaluate("//img[contains(@src, 'car']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for (var i = snapImages.snapshotLength - 1; i >= 0; i--) { var elmImage = snapImages.snapshotItem(i); elmImage.style.MozOutline = "5px solid red"; } 

This example works, but I need a few more conditions. For example (@src, 'bike'), (@src, 'bus'), etc. Again, I apologize for the new question. What is the correct syntax?

Thank you very much!

-Rocki

+4
source share
1 answer

You can use and and or in XPath predicates, for example:

 //img[contains(@src, 'car') or contains(@src, 'bike')] 

Priority is defined in the Booleans section of the specification .

+5
source

Source: https://habr.com/ru/post/1347891/


All Articles