Blake A. Nichols Blake A. Nichols - 5 months ago 24
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.


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