addClass在IE8中不起作用

时间:2014-03-06 11:34:19

标签: jquery

似乎addClass无法使用IE8进行某些重复操作。我创建了一个<div>和一个<p>,我想在点击<p>时将一个类分配给<div>,但它在IE8中不起作用。

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

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

<p>deeded</p>

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

在IE8中没有添加该类。为什么呢?

1 个答案:

答案 0 :(得分:-1)

你没有定义code类,当你在评论中写下(你应该在你的问题中写下这个......)你想把这个类用作标志 < / p>

为此,您应该使用HTML数据属性:

请参阅:http://www.w3schools.com/tags/att_global_data.asp

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

因为您对支持IE8感兴趣

相关问题