That is one way, yes.
Forgotten to say one detail: I've rendered an HTML and wanted to hide layer by clicking on the link.