Angela
Angela

Reputation: 3389

How can I select for an input and a textarea?

I have the following code:

        $('input.update-grid', $form)
            .each(function () {
                var id = this.id.replace('modal', '');
                $('#input' + id).val(this.value)
            })

I would like this to also select for textareas that have a class of upgrade-grid. Is there a way that I can do this without making another selector and code?

Also if I want to set the text in a textarea is that just set in the same way as an input with .val()?

Upvotes: 1

Views: 66

Answers (2)

xdazz
xdazz

Reputation: 160833

You could just select by the class name.

$('.update-grid', $form).each(function () {
   var id = this.id.replace('modal', '');
   $('#input' + id).val(this.value);
})

Upvotes: 1

adeneo
adeneo

Reputation: 318192

$('input.update-grid, textarea.update-grid', $form)

Or if no other element tags have that class:

$('.update-grid', $form)

Upvotes: 2

Related Questions