0

It seems addClass is not working with IE8 for some reaosn. I made a <div> and a <p> , and I want to assign a class to <p> when the <div> is clicked but it is not working in IE8.

.test {
    width: 100px;
    height: 100px;
    background: red;
}

<div class="test"></div>

<p>deeded</p>

$('.test').click(function() {
    $('p').addClass('code');
});

The class does not get added in IE8. Why?

BlekStena
  • 345
  • 3
  • 13
  • 8
    Which version of JQuery are using? JQuery 2.x doesn't support IE 6,7,8. As the [docs](http://jquery.com/download/) says - `jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.`. – Vucko Mar 06 '14 at 11:35
  • the above would work even with jquery 2.x provided that `code` class is defined. Of course jquery 2.x does not attemp to fully support old IEs – Paolo Mar 06 '14 at 11:49
  • Vucko, today i have learned a new thing. THANKS for the tip with ie8 and jquery 2. I replaced that with jQuery v1.12.4 and all my issues with addclass are gone. – Adyyda Jan 23 '17 at 08:07

1 Answers1

-1

You didn't define the code class and as you write in your comment (you should write that in your question..) you want to use the class as a flag

For this purpose you should use the HTML data attribute:

see: http://www.w3schools.com/tags/att_global_data.asp

and: Is there any problem with using HTML5's "data-*" attributes for older browsers?

as you're interested in supporting IE8

Community
  • 1
  • 1
Paolo
  • 15,233
  • 27
  • 70
  • 91
  • No i did not define it. So there is no way to work if it is not defined? Becuase I need it as a flag only, not for styling – BlekStena Mar 06 '14 at 12:01
  • See the edit in my answer... – Paolo Mar 06 '14 at 12:40
  • 1
    How does this answer the question? I understand this is a _different_ way of doing it but it doesn't address why `addClass` isn't working. – Hanna Sep 09 '14 at 20:43
  • @Jonannes `addClass` is not working because the OP didn't defined the CSS class he's trying to add. I thought it was clear from the first sentence. – Paolo Sep 11 '14 at 10:30