Attaching An Event Handler In javascript

2011-05-01

Some times we may need to specify event dynamically to some element at runtime based on run time scenario. For example in my case I need to display a grid with a column having an error description and shown as a linkbutton. On MouseOver on that link button I displayed full error description in a div tag. And then I need to close the div tag if user clicks any where in the grid. So I only need to close the div tag at the click event of grid when Div is displayed. here comes adding/attaching an event to an element dynamically.

Code


var grid = document.getElementById('gdvErrorLog');

grid.onclick = function () { div.style.display='none' };

Works in following

0 comments: