santa santa - 5 months ago 16
jQuery Question

ltrim with jQuery?

I am using jQuery to capture an encoded URL.

I looks something like: #?var=asdasdasdasdasd

I need to strip "#?" at the beginning of the string. In PHP I'd use ltrim. How can I do this with jQuery or plain JS?

$("#myLink").click(function(){
var myUrl = $(this).attr("href");
var cleanUrl = ....

}

Answer

You could use replace method.

var cleanUrl = myUrl.replace(/^#\?/, '');