54.7k views
2 votes
Find an element inside a div using javascript

User Levenal
by
7.8k points

1 Answer

6 votes
You want to find it based on what? Here's a solution if you want to find it based on id:

function GetElementInsideContainer(containerID, childID) {
var elm = document.getElementById(childID);
var parent = elm ? elm.parentNode : {};
return (parent.id && parent.id === containerID) ? elm : {};
}

User Yahya Hussein
by
8.7k points