I have some asp textboxs in a div container. I just want to clear those when i am clicking the CLEAR button.
I say common class 'text' for all textboxes and then wrote this jQuery
$(".text").text("");
It's not working ..
How to do this ? I need the most efficient code .
JavaScript reset(): The reset() method resets the values of all elements in a form (same as clicking the Reset button). The button itself resets the form but, the type-1 and type-2, the reset button should be inside the form and type-3 can be either out or in. Syntax to convert jQuery element to a JavaScript object.
You can use the onfocus attribute in JavaScript to clear a textbox or an input box when somebody sets focus on the field. If you are using jQuery, then use the . focus() method to clear the field.
If you need to clear text boxes values alone, you can change the code like this:
$("#divID").find("input[type=text]").val('');
or
$("#divID").find("input:text").val('');
$('a.clearButton').bind('click', function() {
$('#divId input').val('');
});
Notes:
You should use val() instead of text().
You are asking for efficient code - and using class selector is not efficient.
Either use id, or add tag name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With