开发者

remove first char of a variable with jQuery

开发者 https://www.devze.com 2023-03-22 14:23 出处:网络
I\'m trying to modify a jQuery variable from e.g. /images/tree.jpg to images/tree.jpg (without the first slash, so it should be a relative path instead of an absolute).

I'm trying to modify a jQuery variable from e.g. /images/tree.jpg to images/tree.jpg (without the first slash, so it should be a relative path instead of an absolute).

I get开发者_StackOverflow the URL like this: var href = jQuery("img.thumbnail").attr("href");

Now I need this URL on another place, but without the first char.

Is there an easy way to do this? Thanks!!


var href = jQuery('img.thumbnail').attr('href');  // e.g.  '#foo'
var secondCharacterAndOnward = href.substring(1); // e.g.  'foo'

String.substring

Though I'm not sure why an image tag has a href attribute, to be quite honest...


Use the javascript substring method.

var href = jQuery("img.Thumbnail").attr("href");
    href = href.substring(1);
0

精彩评论

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