In Jquery on click function is not working for img in IE 6
-
05-07-2019 - |
Question
I tried to bind click and animate function on a img tag. Its works fine in firefox. but went wrong with IE. So i simplified the code and tested only for click . Even click function is not clled. Here is my click function for my img tag with class 'arrowimg'.
$('.arrowimg').click(function(){alert("Show me")});
I get this alert in FF but not in IE what might be the problem?
EDIT:here is my HTML generated code for img tag
<img src='http://localhost/gowri/Project/SS4U/public/images/symbols/advartise_right_arrow_NEW.gif' id="next" class="arrowimg" alt="advartise_right_arrow" />
Solution
Make sure it's in the document ready event and then you end the alert with a semi colon.
$(document).ready(function() {
$('.arrowimg').click(function(){alert("Show me");});
});
EDIT: Looks like there's something up with your markup:
You've got double quotes around 'advartise_right_arrow_NEW.gif'.
Should it be this instead:
<div id="nextdiv">
<img src="<?php echo _SS4U_SYM.'advartise_right_arrow_NEW.gif'; ?>"
id="next" class="arrowimg" alt="advartise_right_arrow"/>
</div>
OTHER TIPS
Generally, IE6 should be able to handle this. Make sure that you're getting any matches at all for your selector
alert($('.arrowimg').length);
If not, there may be something else that have gone wrong at an earlier stage.
Try this,
$('.arrowimg').click(function(event){
event.preventDefault();
alert("Show me");
});
Just for the future reference: Check your jQuery version and your jQuery syntax.
Using jQuery 1.6 and
$('#elem_id').on('click', function(){ });
will not working because of on function. Error: 'undefined' is not a function
Use
$('#elem_id').click(function(){ });
instead or upgrade to a newer jQuery version. https://developers.google.com/speed/libraries/devguide#jquery