Problem with events in Firefox

I have a problem accessing an "event" in Firefox. The following code works fine in Chrome, but in Firefox I get an "event not defined" error.

<tr onclick="rowSelected('thisRowType')">
  ... row content ...
</tr>

<script type="text/javascript">
    function rowSelected(type) {
        var eventRow = event.currentTarget; // here I get the error
    }
</script>

I understand that Firefox does not find any variable called an event, but I could not find anything in Firefox other than an "event".

So, how can I access the current event in Firefox or what should the redesign look like? Note that I have different strings containing different values ​​for the type.

+3
source share
1 answer

Try this instead:

function rowSelected(event, type) {
    var eventRow = event.currentTarget; // here I get the error
}

You do not allow passing an argument to the event. Well, you were, but it was passed to a type variable. Now it eventwill contain a value currentTarget.

EDIT

Oh wait! You also want to pass a string type.

That should do it!

<tr onclick="rowSelected(event, 'thisRowType')">
  ... row content ...
</tr>

<script type="text/javascript">
    function rowSelected(event, type) {
        var eventRow = event.currentTarget; // here I get the error
        alert(type);
    }
</script>
+5
source

Source: https://habr.com/ru/post/1784685/


All Articles