开发者

Remove # from value (jQuery)

开发者 https://www.devze.com 2023-01-05 04:01 出处:网络
var current = $(this).attr(\'href\'); alert(current); shows the value with \'#\' eg \'#target\' instead of just \'target\',开发者_运维知识库 what do I modify in the code?
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


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


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

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


As easy as this, just use replace:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号