adding conditional statements around selected tree javascript