'Cheerio find child with class that starts with string
Currently I have an object which has a lot of children. I can find a particular child using:
$(elem).find('.animal-type').text();
However, some of the animal-type
classes have different endings: i.e. animal-types, animal-type1 or longer ones
.
How can I substitute find('.animal-type')
to look for elements that have a class which starts with animal-type
?
Solution 1:[1]
If you want to select all html elements that have a class which starts with 'animal', this should work: $(elem).find('[class^="animal"]')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dragos |