jQuery hide all elements with the same id





Add maxlength on textArea using jQuery

The Low Down

The maxlength attribute limits the number of characters that an <input> or<textarea> can accept. The maxlength attribute on textarea is new in HTML5.

  • Works for GUI-less inputs like text, email, url, search, tel and password.
  • Upon data entry, browsers will not permit the user to enter more than the characters defined by the value of the maxlength attribute: cutting off the text as-you-type and truncating pasted text. This can lead to bad user experience.
  • maxlength does not limit placeholder length.
  • If a preset value is included with a value that has more characters than the allowed length, a validation error will not be thrown. However, if that preset value is edited, yet is still longer than the allowed length, the element will become invalid, matching the :invalid pseudoclass selector, and will be prevented from being submitted in both Opera and IE10+, which both display the tooLong validity error message.
  • IE 9 reported support on both inputs and textareas but only works on inputs.

Source: https://www.wufoo.com/html5/attributes/03-maxlength.html


The textArea “maxlength” attribute is supported in HTML 5, the problem is not all browsers support HTML 5, especially, the old IE.


jQuery Example

A jQuery example to implement the “maxlength” effect on a textarea field.

<script language="javascript" type="text/javascript"
<script language="javascript" type="text/javascript">

    $(document).ready( function () {

	maxLength = $("textarea#comment").attr("maxlength");
" + maxLength + " remaining
); $("textarea#comment").bind("keyup change", function(){checkMaxLength(this.id, maxLength); } ) }); function checkMaxLength(textareaID, maxLength){ currentLengthInTextarea = $("#"+textareaID).val().length; $(remainingLengthTempId).text(parseInt(maxLength) - parseInt(currentLengthInTextarea)); if (currentLengthInTextarea > (maxLength)) { // Trim the field current length over the maxlength. $("textarea#comment").val($("textarea#comment").val().slice(0, maxLength)); $(remainingLengthTempId).text(0); } }
</script> </head> <body> <h1>TextArea maxlength with jQuery</h1> <textarea id="comment" maxlength="10" rows="10" cols="60" ></textarea> </body> </html>


Source: http://www.mkyong.com/jquery/add-maxlength-on-textarea-using-jquery/






Asc/Desc tooltip on sorting columns?


if (($(this).hasClass(‘sorting’)) || ($(this).hasClass(‘sorting_desc’))) {
$(this).attr({title: ‘Sort Ascending’});
} else {
$(this).attr({title: ‘Sort Descending’});


Source: https://datatables.net/forums/discussion/718/asc-desc-tooltip-on-sorting-columns


Button type “button” vs. “submit”

The type of the button. Possible values are:

  • submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
  • reset: The button resets all the controls to their initial values.
  • button: The button has no default behavior. It can have client-side scripts associated with the element’s events, which are triggered when the events occur.







jquery detect textbox value change NOT based on user input



var $myText = $(“#myText”); $myText.data(“value”, $myText.val()); setInterval(function() { var data = $myText.data(“value”), val = $myText.val(); if (data !== val) { $myText.data(“value”, val); alert(“changed”); } }, 100);