Peter
Peter

Reputation: 11835

Jquery click - e.target.classList on IE is undefined

demo
http://jsfiddle.net/bRqAR/2/

this code did not work on the internet explorer (check console).
How can i fix this?

html

<div id="myDiv_1451" class="allDivs">
Hello
    <div class="iconDiv"><img src="http://jsfiddle.net/img/keys.png" /></div>
    <div style="clear:both;"></div>
</div>

JS

$(document).ready(function() {

    $('.allDivs').click(function(e)
    {
         var divId = this.id.replace(/myDiv_/gi,'');

         if(e.target.classList[0] == 'iconDiv' || e.target.parentElement.className == 'iconDiv')
         {
           alert('click on green iconDiv or on icon');
         }
         else
         {
           alert('click on main');
         }
    });                                              
 });

Thanks in advance!

Upvotes: 0

Views: 1284

Answers (2)

Satya
Satya

Reputation: 8881

IE gives this error : Unable to get value of the property '0': object is null or undefined , so change e.target.classList[0] to e.target.classList == 'iconDiv'

Upvotes: 1

riso
riso

Reputation: 232

I've tried on IE,

delete the [0] e.target.classList[0] > replace with e.target.classList == 'iconDiv'

works on chrome and IE

Upvotes: 1

Related Questions