点击<a> tag

时间:2018-03-09 07:36:38

标签: javascript jquery ios css cross-browser

I have the following jQuery code to add a class to a anchor tag when its clicked, the objective is to give the anchor tag a border bottom:

$(".breadcrumbs > li > a").click(function(){
     $(this).addClass('hoveractive');
});

on Ios this class is never added and so the styles are not applied, Rest of the code is below:

.breadcrumbs > li > a.hoveractive {
    border-bottom : 1px solid #f05034;
}

HTML::-

<ul class="breadcrumbs">
     <li><a href="/en">Home</a></li>
     <li><a href="/en/about-desuninr">About Desunin<sup>®</sup> </a></li>
     <li>Interesting links</li>
 </ul>

basically i just want the class to be added for a fraction of a secound before the page refreshes and goes to the next link, but this does't seem to be happening.

If i change my code to the below,

$(".breadcrumbs > li > a").click(function(){
     $(this).addClass('hoveractive');
     return false;
});

I.E. include a return false statement , then the class is added in ios, but that's ofcourse not what i want to be doing , so to summerise my question why is my addClass not working in ios ?

1 个答案:

答案 0 :(得分:0)

尝试绑定文档中的click事件,看看是否有帮助,

$(document).on('click', '.breadcrumbs > li > a', function(){
 $(this).addClass('hoveractive');
});