2
Hi. I have a problem with IE8. The code below works on Chrome and firefox, but not on IE. As soon as it reaches that first line, the IE error says "expected object".
What I have is an img inside 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 inside 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 HTML is a menu. And an empty div#Prods. When I click on a menu link, it calls a PHP function by ajax to display the contents of a folder within #Prods.
The PHP code places inside #Prods:
- a series of imgs that are thumbnails (these are the imgs tested in the function qd clicked);
- a "p";
- an "img" which is the #img-display;
OBS.: the variable "eh_tb" stores which thumbnail is currently displaying its content. It is just not to load the function and end up loading the same content again.
I had to use Event.target because the content is dynamically generated by PHP. Someone has a solution for this code to run on IE8?
What is this
find("img")
? And you can usethis
, butevent.target
should work, jQuery normalizes it.– bfavaretto
Test this code: http://jsfiddle.net/Sergio_fiddle/a4rLmb8m/ - the reason to use a library like jQuery is to be compatible on different browsers. Unless you are using version 2.0 IE should work well. But as bfavaretto said,
find(img)
is wrong there– Sergio
Related: http://answall.com/questions/63395/quando-usar-this-e-quando-usar-event-target
– Wallace Maxters
Related: http://answall.com/questions/51206/qual-a-diferen%C3%A7a-do-this-e-do-Event-target/51207#51207
– Wallace Maxters