exlracted function for each node in javascript