The wierdest thing.
I have a function which calls:
var clicked_el = event.target.id;
This function breaks at this line in FireFox. It works in ie9, but not in 8 (because ie8 uses srcElement instead). Every attempt to grab the id of the element which initiated the event has been a complete flameout on my end.
I think there is a way that jQuery smoothes out browser incosistencies with jQuery.Event but I can’t get anything working.
Can anyone tell me a better browser consistent method to do this?
here is the function, it’s part of my backbone view.
open: function () {
iconState = true;
var self = this;
var clicked_el = event.target.id;
$('div.hr, div#footer_icons').animate({
top : '-=300'
}, 500, function () {
if (innerContentIsVisible === false) {
$('#a_close').fadeIn(500);
}
});
$('div#article').animate({
opacity : 0
}, 500,function () {
self.load_content(clicked_el);
});
},
UPDATE
The open function was being called from another function, and I forgot to pass the event paramater when I invoked the open function, which is why it was returning undefined.
here is the function which now passes the event param:
click: function(event) {
if (iconState === false) {
this.open(event);
} else {
var self = this;
var clicked_el_icon = event.target.id;
$('div#loaded_content').fadeOut(250, function() {
self.load_content(clicked_el_icon);
});
}
},
open: function (event) {
iconState = true;
alert(event);
var self = this;
var clicked_el = event.target.id;
$('div.hr, div#footer_icons').animate({
top : '-=300'
}, 500, function () {
if (innerContentIsVisible === false) {
$('#a_close').fadeIn(500);
}
});
$('div#article').animate({
opacity : 0
}, 500,function () {
self.load_content(clicked_el);
});
},
Thanks… I will not forget this lesson.
You have to declare “event” as the parameter for the “open” handler function.