JQuery clear Values ​​in Div

I have a DIV that contains a lot of input text.

I need a way in jQuery 1.3.2 to clear all values ​​inside onclick input.

Therefore, when I click on a specific link, all input values ​​inside this DIV will be cleared.

I don't have sample code, I just need to know if there is a way to clear all input values ​​that are inside a specific DIV (not in FORM, but in DIV).

thank

+3
source share
6 answers

Yes there is

html like

<div id="div_id">
    <input type="text" value="foo" />
    <input type="text" value="foo" />
    <input type="text" value="foo" />
    <input type="text" value="foo" />
</div>

then jQuery

$('#div_id input[type="text"]').val('');

working demonstration

+7
source

What are these inputs? Textboxes? Maybe this

$("#DivID input:text").val("");

Demo

+3
source

div

 function clear_form_elements(id_name) {
  jQuery("#"+id_name).find(':input').each(function() {
    switch(this.type) {
        case 'password':
        case 'text':
        case 'textarea':
        case 'file':
        case 'select-one':       
            jQuery(this).val('');
            break;
        case 'checkbox':
        case 'radio':
            this.checked = false;
    }
  });
}
+1

val proerpty .

- :

$("input[type='text']", "#<YOUR_DIV_ID>").val("");

:

<div id="textDiv">
    <input type="text" Value="1"/> <br/>
    <input type="text" Value="2"/> <br/>
    <input type="text" Value="3"/> <br/>
    <input type="text" Value="4"/> <br/>
    <input type="text" Value="5"/> <br/>
    <input type="text" Value="6"/> <br/>
    <a name="clickMe" href="javascript:void(0)">Empty Boxes</a>
</div>

<script type="text/javascript">
    $(function(){
     $("a[name='clickMe']").click(function(){
        $("input[type='text']", "#textDiv").val("");
     });
    });
</script>

@: http://jsfiddle.net/DKwy8/

0
$('linkselector').onClick(function() {
    $('#DivId input').val('');
});
0

HTML

<div id="myDiv">
    <input type="text" value="One">
    <input type="text" value="Two">
    <input type="text" value="Three">
</div>
<a href="#" name="ClearDiv" id="clearDiv">Clear</a>

JQuery

$('a#clearDiv').bind('click', function() {        
    var $div = $('div#myDiv');
    $('input[type="text"]', $div).each(function() {     
      $(this).val('');
    });

});

DEMO

0

All Articles