Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping through textboxes using jquery

How can I go about in clearing these textboxes by looping through them using Jquery?

<div class="col-md-4" id="RegexInsert">
    <h4>New Regex Pattern</h4>
    <form role="form">
        <div class="form-group">
            <label for="firstName">Desription</label>
            <input type="text" class="form-control" id="txtRegexDesription" placeholder="Description" />
        </div>
        <div class="form-group">
            <label for="firstName">Regex pattern</label>
            <input type="text" class="form-control" id="txtRegexPattern" placeholder="Regex pattern(C#)" />
        </div>
        <div class="form-group">
            <label for="firstName">Data type</label>
            <input type="text" class="form-control" id="txtDataType" placeholder="Data type" />
        </div>
        <button type="button" class="btn btn-default btn-sm btnAddRegexPattern" data-applicationid=""><span class="glyphicon glyphicon-plus"></span>&nbsp;Add</button>
    </form>
</div>

I am doing the following which is not quite there yet.

$("#RegexInsert .inputs").each(function () {
    $('input').val('');
});

kind regards

like image 451
Arianule Avatar asked Nov 28 '22 13:11

Arianule


1 Answers

You don't need a loop, you can do it in a single selector:

$('.form-control').val('');

I'm not sure where .inputs in your example is coming from as it is not in your HTML. You can make the selector more generic if required:

$('#RegexInsert input[type="text"]').val('');
like image 129
Rory McCrossan Avatar answered Dec 16 '22 06:12

Rory McCrossan