Add Class to parent, jquery and IE9

255 views Asked by At

So simple, but can't get this to work in IE9. Ive read tons of answers and nothing seems to work. I just need to add a class to an elements parent, seems simple right? In all other browsers, this does the trick:

$('#trigger').click(function(e){
    e.preventDefault();
    $(this).parent().addClass('bar');
});

Not in IE9. The solutions Ive found don't work either:

$('#trigger').click(function(e) {
    e.preventDefault();
    var item = $(this).closest("li");
    $(item).addClass('bar');
});

Here's a fiddle to try in IE9

1

There are 1 answers

0
Ishu Khullar On

This is working in IE9

$('#trigger').click(function(e) {
 e.preventDefault();
   var item =$(this).parent('li');
    $(item).addClass('bar');
});
<ul>
    <li class="foo">
        <a href="javascript:void(0)" id="trigger">click me</a>
    </li>
    <li>other shit</li>
</ul>