javascript - how to make div contain a certain number of characters? -
i have contenteditable div, want create value size 10, div can't contain more 10 characters, possible? if yes, how in html or js?
you can't in html, there's no size attribute works way, when using input:text element. have utilize javascript. here illustration in jquery:
$('#my-div.contenteditable').text(function(idx, txt) { homecoming txt.substr(0, 10); }); you additionally utilize css ensure have tight fit around text, since different fonts/font sizes yield different widths, despite 10 character constraint:
css:#my-div.contenteditable{ padding:0; left-margin:auto; right-margin:auto; } javascript jquery html
No comments:
Post a Comment