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!!
You can also remove the first character from a string using substring method. let input = "codehandbook" function removeCharacter(str){ return str. substring(1) } let output = removeCharacter(input); console. log(`Output is ${output}`);
text(). replace('-', '') );
To remove the first word from a string, call the indexOf() method to get the index of the first space in the string. Then use the substring() method to get a portion of the string, with the first word removed.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With