2

Several elements in a page have the id=myid. I want to find the element having the value text = "findme". But how?

<div id="myid">some</div>
<div id="myid">findme</div>

document.querySelectorAll("div[id='myid']"); //TODO how to match value=findme?

Only native JS, not jquery.

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • 1
    @MichałPerłakowski It's not a duplicate. I want to find the element explicit having the text value "findme". The code above returns already all elements having the certain id. – membersound Jun 09 '17 at 09:43
  • 1
    It is a duplicate. I've fixed the pointer to aim at the right question. – Quentin Jun 09 '17 at 09:43
  • 1
    "Several elements in a page have the id=myid." — Don't do that. Write HTML instead. – Quentin Jun 09 '17 at 09:45
  • @Quentin I know, but I'm not in control of the page – membersound Jun 09 '17 at 09:50
  • here is your answer @membersound please visit https://jsfiddle.net/sunnysm/2ad75u9q/ – Sunny S.M Jun 09 '17 at 10:03
  • In general you HTML is invalid if you are using IDs more than one time. A ID must be unique! Use validation services to check your HTML! If you want to mark many elements then us a class or a name to find all instances. – coding Bott Jun 16 '17 at 12:18

0 Answers0