Skip to content

Instantly share code, notes, and snippets.

@jagroop
Created January 16, 2018 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagroop/6b87a62a9ec2c0c5de1ac9a16e6d70f8 to your computer and use it in GitHub Desktop.
Save jagroop/6b87a62a9ec2c0c5de1ac9a16e6d70f8 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<input type="text" id="sample-text" value="Lorem ipsum dolor sit amet">
<input type="checkbox" id="cb">
<p id="result"></p>
<script>
$(document).ready(function(){
$('#cb').change(function(e){
e.preventDefault();
var str = $('#sample-text').val(function(i, t) { return t.substr(0, 4); });
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment