Search code examples
javascriptjqueryfirefoxprototypejs

TypeError: param.toElement is undefined


Hey all I have the following code that's a mix of Prototype JS and Jquery:

var oldZindex = 0;
var theClickID = null;

UIProgressButton.prototype._initEvents = function() {
    var self = this;
    this.button.addEventListener( 'click', function(param) {
        $('#overlay').css({'visibility':'visible'});
        theClickID = $('button[data-id="' + param.toElement.attributes[1].value + '"]').parent().attr('id');
        oldZindex = $('#' + theClickID).css('z-index');
    });
}

This code works just fine in a Chrome Browser but seems to throw the error of:

typeerror param.toelement is undefined

In FireFox.... How would I go about fixing this issue since I know for a fact that it does work since its working in Chrome just fine?


Solution

  • Fixed it by adding the following:

    var Element = ((window.event)?(event.srcElement):(evt.currentTarget));
    

    Then using that within my code:

    UIProgressButton.prototype._initEvents = function() {
        var self = this;
        this.button.addEventListener( 'click', function(param) {
            $('#overlay').css({'visibility':'visible'});
            var Element = ((window.event)?(event.srcElement):(param.currentTarget));            
            theClickID = $('button[data-id="' + Element.attributes[0].value + '"]').parent().attr('id');
            oldZindex = $('#' + theClickID).css('z-index');
        });
    }