substring()
methodYou can use the JavaScript substring()
method to remove first character form a string. A typical example is removing hash (#
) character from fragment identifier.
Let's check out an example to understand how this method basically works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Remove first Character from String</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$("a").click(function(){
var fid = $(this).attr("href");
var itemId = fid.substring(1, fid.length);
alert("The ID of the linked image is - " + itemId);
});
});
</script>
</head>
<body>
<a href="#balloons">Show Balloons</a>
<br>
<img src="balloons.jpg" style="margin-top: 1000px" alt="Hot Air Balloons" id="balloons">
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to make Custome Log System in Laravel?
In this article, I will share with you h...Laravel 8 PHP Guzzle Http Client GET and POST Examples
To make request from the application we...How To Connect MongoDB in Express Application
In this article, i will share with you h...How to add attributes to an HTML element in jQuery
Use the jQuery attr() method You can...Failed to listen on 127.0.0.1:8000 (reason: Address already in use)
Laravel is the most popular and open-sou...