Jquery event.target does not work in IE8

2

Hi. I have a problem with IE8. The code below works in chrome and firefox, but not in IE. Once it arrives on that first line, the IE error says "expected object."

What I have is an img within a div # prods. When clicked, this code tests [if what was clicked is an img "& &" if its id is different from "# img-display" (id of another img within the div that should not trigger the function) & & if the id is different from the value of eh_tb].

$('#prods').on('click', find("img"), function(event) {
    if( $(event.target).is('img') && ($(event.target).attr('id') != 'img-display') &&
($(event.target).attr('id') != eh_tb) ) {

        //PROCESSAMENTO AQUI
    }                                              
});

What's in the HTML is a menu. And an empty div # prods. Qd I click on a menu link, it calls a PHP function by ajax to display the contents of a folder inside #prods.

The PHP code puts it inside #prods:

  • a series of imgs that are the thumbnails (these are the imgs tested in the function qd clicked);
  • a "p";
  • an "img" which is # img-display;

NOTE: The variable "eh_tb" holds which thumbnail is currently displaying your content. It's just not to load the function and end up loading the same content again.

I had to use event.target because the content is generated dynamically by PHP. Does anyone have a solution for this code to run in IE8?

    
asked by anonymous 13.08.2014 / 23:18

1 answer

2

jQuery (in versions 1.x) works the same way in IE8 and other more modern browsers. This is a great advantage of using a library.

That said, your problem is in the code. Remove find("img") and only put "img" as @bfavaretto indicated . So delegate the event and this alone will already make it possible to remove its first condition in its if .

My code suggestion is:

$('#prods').on('click', "img", function(event) {
    if (this.id == 'img-display' || this.id == eh_tb) return false;
    //PROCESSAMENTO AQUI

});
    
13.08.2014 / 23:41