Q:

How to remove first character from a string in jQuery

0

How to remove first character from a string in jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the JavaScript substring() method

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to stop firing event until an effect is finish... >>
<< How to check or uncheck radio button dynamically u...