Blake A. Nichols Blake A. Nichols - 1 year ago 173
Javascript Question

jquery get children by attribute

This code is returning an empty array when I run it even though there is a div with the attribute [data-directory] in the container.

$(container).children( '[data-directory]' )

container is valid, and the children are there when I log $(container), I'm not sure why it isn't pulling the child that is there though.

Answer Source

please check to see whether container is a valid and exists if it does. then probably $(container).find( '[data-directory]' ) would do

.children would only look in the immediate children. where as .find will go through all the descendants which i think is what you want

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download