The solution has two parts. 1. Wrap every tree node title into ``. Then we can CSS-style them on `:hover` and handle clicks exactly on text, because `` width is exactly the text width (unlike without it). 2. Set a handler to the `tree` root node and handle clicks on that `` titles.