Tutorial :Remove # from value (jQuery)



Question:

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


Solution:1

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


Solution:2

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

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


Solution:3

As easy as this, just use replace:

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »