mardi 29 décembre 2015

Find div inside div

I want to find child3 is exists in parent2 or not. If child3 exists it will show alert "exists" otherwise "element doesnt exists". But it seems if/else statement not working. I use alert before if/else to test function working or not. Following is my code

<!DOCTYPE html>
<html>
<body>

<div class="parent1">
<div class="child1">Child1</div>
<div class="child2">Child2</div>
<div class="child3">Child3</div>
</div>

<div class="parent2">
<div class="child1">Child1</div>
<div class="child1">Child2</div>
</div>

<button onclick="find()">search</button>



<script>
function find()
    {
alert('testing function working');

if($collection.children().is(".child3")){ alert('exists');}

else{alert('Element doesnt exists');}
    }
</script>

</body>
</html>

Aucun commentaire:

Enregistrer un commentaire