Replace jQuery click event for legend with standard JS