user1260827
user1260827

Reputation: 1520

find elements which have the some id pattern

I generate markup dynamically and id for inputs elements:

<div class="wrap_input fancy_form" style="margin-bottom: 10px; margin-top: 28px;">
        @foreach(var seatType in Model.UsingSeatType)
        {
            int i = 1;
            <p class="inp_label" style="width: 50px;">@(seatType.Value):</p>
            <i>&nbsp;</i>
            <input type="text" id="type@(i)" value="" data-price=""  style="width: 50px;" />
            i++;
        }
    </div>

How can I find all this inputs(type1, type2, type3 and so on)?

 $("#type?").spinner(); 

Thanks.

Upvotes: 0

Views: 1583

Answers (3)

filype
filype

Reputation: 8380

How about you make the following changes:

Add a class to your input:

<input class="seat_type" type="text" id="type@(i)" value="" data-price=""  style="width: 50px;" />

Use jQuery selector on the class

$(".seat_type").spinner();

I suggest these changes because it would be easier to read for most people.

Upvotes: 2

tobias86
tobias86

Reputation: 5029

You can try this:

$('input[id^="type"]').spinner();

More info here.

Upvotes: 0

The System Restart
The System Restart

Reputation: 2881

Just try this code

$('.wrap_input.fancy_form input[type=text][id^=type]').spinner();

Upvotes: 2

Related Questions