Reputation: 51
So I am having trouble with my onclick in IE. It works in all other browsers except for IE. Any suggestions would help. Here is my code. It is calling an xml file to show the images in an array and then the nextImage and prevImage are the buttons to click. Here is my code.
function setImage(arrayPOS){
$('#slideimage').attr('src', iArray[arrayPOS]);
$('#slideimage').attr('alt', aArray[arrayPOS]);
var nextPOS;
var prevPOS;
if (arrayPOS === num){
nextPOS = 0;
}
else {
nextPOS = arrayPOS + 1;
}
if (arrayPOS === 0){
prevPOS = num;
}
else {
prevPOS = arrayPOS - 1;
}
$('#nextImage').attr('onclick', 'setImage(' + nextPOS + ')');
$('#prevImage').attr('onclick', 'setImage(' + prevPOS + ')');
}
Upvotes: 1
Views: 113
Reputation: 20842
To allow for some flexibility (and to keep you sane) you can bind your onclick
event handler using a selector to grab your element and bind
to it:
// ...
// Get the element and bind a click event to it
$('#nextImage').click(function(){
setImage( nextPOS );
});
// Same goes for #prevImage
The above method allows for a much more flexible (and cross browser) way of handling your events.
Upvotes: 1