0

I have an HTML div element in my application as follows:

<div id="DivId" contenteditable="true" style="border:1px solid black"></div>

I need to limit the number of characters that can be typed in the div. Like giving the maxlength attribute a to textbox. How can I do this? It would be very helpful if I would be able to do it without using JavaScript or jQuery.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sudha
  • 2,078
  • 6
  • 28
  • 53

1 Answers1

-1

There are some CSS attributes like max-height or max-width which do limit the width for block level elements.

So you can code this out like this:

<div style='max-width:100px'>Content</div>
<span style='max-width:100px; display:block;'>Content</span>

But be careful, as they do not properly support Internet Explorer 6: Refer to min-width and max-width.

But if you just mean the length of the content, I am sorry to say that you can't do that in HTML. You need to use a piece of JavaScript to do this. Take a look at jQuery; it's really easy to do.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
The Dark Knight
  • 5,455
  • 11
  • 54
  • 95