<div id="errorBar" onclick="(new selectElement(this)).hide()">123</div> <script> function selectElement(element) { this.hide = function () { element.style.display = 'none'; } } </script>