Reputation: 3915
$('.mydesc').keyup(function () {
var len = $(this).val().length;
if(len == 63){
//put line break here
}
});
on reaching 63 characters including space the cursor should b moved to next line (effect when i get enter button)
how can i do it in jquery ?
Upvotes: 2
Views: 406
Reputation: 62488
do something like this:
if(len == 63){
$(this).val($(this).val() + "\n");
}
Upvotes: 0
Reputation: 93551
You probably want something like this:
$('.mydesc').keyup(function () {
var $this = $(this);
var val = $this.val();
var lines = val.split('\n');
var result = [];
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
while (line.length > 5) {
result.push(line.substring(0, 5));
line = line.slice(5);
}
result.push(line);
}
$this.val(result.join('\n'));
});
Just change the 5's to the length you want.
Upvotes: 0
Reputation: 38102
You can add line break using \n
when reach 63
characters:
$('.mydesc').keyup(function () {
var len = $(this).val().length;
if (len == 63) {
this.value += '\n';
}
});
Upvotes: 1