javascripthtmldomelement

Selecting Elements By InnerHTML with querySelector


Is there a way to select an element by innerHTML without using loops? Can it be done using something like

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

or

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

Solution

  • 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")')