
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Substring of a String in jQuery
To get substring of a string in jQuery, use the substring() method. It has the following two parameters:
- from: The from parameter specifies the index where to start the substring.
- to: The to parameter is optional. It specifies the index where to stop the extraction. This is an optional parameter, which extracts the remaining string, when nothing is mentioned.
Example
You can try to run the following code to learn how to get substring of a string in jQuery:
<html> <head> <title>jQuery subtring</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#button1").click(function(){ var str1 = "Hello World!"; var subStr = str1.substring(0, 5); alert(subStr); }); }); </script> </head> <body> <p>Hello World!</p> <button id="button1">Get substring</button> </body> </html>
Advertisements