This could be improved using `toggleClass`

    child.toggleClass(collapsedClass);
    child.toggleClass(expandedClass);