Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Get Substring from a String</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ var myStr = $("p").text(); var subStr = myStr.substring(4, 20); $("button").click(function(){ alert(subStr); }); }); </script> <style> .show-read-more .more-text{ display: none; } </style> </head> <body> <p>The quick brown fox jumps over the lazy dog</p> <button type="button">Get Substring</button> </body> </html>