最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cleanest way to remove href from anchor with jQuery - Stack Overflow

programmeradmin2浏览0评论

So,

I am currently removing and adding a class to an anchor with this:

$('#link a').removeClass('btn').addClass('scroll');

But I also need to remove the href in the '#link a' anchor tag too.

What's the cleanest/neatest way to acplish it all?

So,

I am currently removing and adding a class to an anchor with this:

$('#link a').removeClass('btn').addClass('scroll');

But I also need to remove the href in the '#link a' anchor tag too.

What's the cleanest/neatest way to acplish it all?

Share Improve this question asked Mar 13, 2015 at 2:18 causticcaustic 5852 gold badges8 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You can use .removeAttr() function

 $('#link a').removeClass('btn').addClass('scroll').removeAttr('href');

Just going by your description I might try .toggleClass() just to be a bit cleaner.

$('#link a').toggleClass('btn scroll').removeAttr('href');
发布评论

评论列表(0)

  1. 暂无评论