Remove # from value (jQuery)

…衆ロ難τιáo~ 提交于 2019-12-24 00:31:02

问题


var current = $(this).attr('href');
alert(current);

shows the value with '#' eg '#target' instead of just 'target', what do I modify in the code?

Thanks


回答1:


var current = $(this).attr('href').slice(1);
alert(current);



回答2:


I assume you're dealing with a <a> element?

this.hash.substring(1); // yes, it's that simple...



回答3:


As easy as this, just use replace:

var current = $(this).attr('href').replace('#','');


来源:https://stackoverflow.com/questions/3156077/remove-from-value-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!