vendredi 23 octobre 2020

How to find out if A contains B? In javascript

Let's say I have two divs A and B.

<div id="A">1253555</div>

<div id="B">1</div>

I have to find out if A contains B.
In this example, it will be the answer of (if 1253555 contains 1 ), which should be true.
Then i have to execute function doSomething().

function doSomething() {

  var x  =  document.getelementById("A").innerHTML;

  var y  =  document.getelementById("B").innerHTML;

  if (=...) { 
 // I dont know how to code here now...i tend to use indexof

}

Please guide me further.
Please use a method in pure javascript and works best for all browsers.

Aucun commentaire:

Enregistrer un commentaire