adviner
adviner

Reputation: 3567

JQuery nextAll reading all the input fields

I have following html:

<input type="text" id="entry1" value="1" />
<input type="text" id="entry2" value="2" />
<input type="text" id="entry3" value="3" />
<input type="text" id="entry4" value="4" />
<input type="text" id="entry5" value="5" />
<input type="text" id="entry6" value="6" />
<input type="text" id="entry7" value="7" />

<input type="button" id="test" value="Test 1" />

..
$('#test').click(function () {
  var entrys = $(':text[id != "entry5"]').nextAll(':text');
});

What I was hoping was that it would return entry6, entry7 only. But what I'm getting is basically all the text input fields. What am I doing wrong? Or am I using nextAll() incorrectly? I'm using entry5 as an example but what I want to do is get the fields only after a certain input text id. So if I set it to entry6 only return entry7.

Upvotes: 0

Views: 351

Answers (2)

Blazemonger
Blazemonger

Reputation: 92983

You meant to use = instead of !=:

var entrys = $('input:text[id="entry5"]').nextAll('input:text');

However, Arun's solution is simpler and more appropriate in this case.

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388436

You can use the id selector since you have an id for the input field. You problem was you were using != instead of =.

In this case you don't have to use attribute selector since you are using id as the attribute, you have a built in id selector.

$('#test').click(function () {
    var entrys = $('#entry5').nextAll(':text');
});

Demo: Fiddle

Upvotes: 1

Related Questions