Fixing bug with disable/enable ancestors in javascript