m4mpfi
m4mpfi

Reputation: 51

remove first char of a variable with jQuery

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 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!!

Upvotes: 5

Views: 27349

Answers (2)

Brad Christie
Brad Christie

Reputation: 101614

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...

Upvotes: 23

ShankarSangoli
ShankarSangoli

Reputation: 69905

Use the javascript substring method.

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

Upvotes: 6

Related Questions