javascript - jQuery .find() inputs of multiple types - Stack Overflow

I'm using the following jQuery to clone a set of input fields (1 Select field, 2 Text fields and 1

I'm using the following jQuery to clone a set of input fields (1 Select field, 2 Text fields and 1 Number field)

$("#add_button").click(function(e) {
    e.preventDefault();
    $(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text']").val("");
});

Is there any way I can extend this so the cloned number fields don't also contain the values.

I've tried

$("#add_button").click(function(e) {
    e.preventDefault();
    $(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text|number']").val("");
});

Which doesn't work.

I'm using the following jQuery to clone a set of input fields (1 Select field, 2 Text fields and 1 Number field)

$("#add_button").click(function(e) {
    e.preventDefault();
    $(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text']").val("");
});

Is there any way I can extend this so the cloned number fields don't also contain the values.

I've tried

$("#add_button").click(function(e) {
    e.preventDefault();
    $(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text|number']").val("");
});

Which doesn't work.

Share Improve this question asked Jan 4, 2016 at 14:31 LukeLuke 3,5616 gold badges40 silver badges64 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

The selector in .find("input[type='text|number']") is incorrect. To select multiple elements, separate the selectors by ma.

.find("input[type='text'], input[type='number']")

See Multiple Selectors


To set empty string as value to all the input elements, use element selector.

.find('input').val('')

You must use a multiple element selector using , to separate each selector; like:

$("#add_button").click(function(e) {
    e.preventDefault();
    $(".form-row :first").clone().insertAfter(".form-row :last").find("input[type='text'], input[type='number']").val("");
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745440302a4627799.html

相关推荐

  • javascript - jQuery .find() inputs of multiple types - Stack Overflow

    I'm using the following jQuery to clone a set of input fields (1 Select field, 2 Text fields and 1

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信