'event.srcElement is null in Internet Explorer 8

We are using asp.net webforms. Server is generating input element (image) with onclick event. When click occurs I'm calling function and passing event object into it.

Inside that function I am trying to access event.srcElement.className to get the class name of the element that caused the event. Only in IE8 event's srcElement is null.

What would be the possible solution to this problem?

How can I get the class name of the element that caused the click event inside the function that is called when event occurs?

Selected answer solves my problem but doesn't answer the question!



Solution 1:[1]

Instead of using the event, just pass the clicked element to the javascript function.

<input type="button" onclick="func(this)" value="Ok" class="myClass"/>

Then directly access the element's style class.

<script>
    function func(elem) {
        alert(elem.className);
    }
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 prageeth