Selecting Elements By InnerHTML with querySelector

2019-08-06 06:34发布

问题:

Is there a way to select an element by innerHTML withtout using loops . Can it be done using Something like

document.querySelector('div[innerHTML="Sometext"]')

or

document.querySelector('div[textcontent="Sometext"]')

回答1:

I used jq "contains" to achieve this. for example if i want to get anchor tag with some inner Html then i would do something like this

 $('a:contains("sometext")')