1

I want to get all the values contained in some input texts. The Ids of the inputs are something like something_#index#_value assuming that #index# is an integer so the first Id is something_1_value.

This is what I've tried so far :

$("input[id$='_value'] [id*=i]").each(function (j, el) { // Some actions }

Assuming that i is an int, the selector doesn't return any value, and when I delete the [id*=i], I get all the element where the Id finishes with _value.

So how can I get the values of elements that finishes with _value AND containes the integer i in it's Id?

3
  • 1
    use string concatenation - $('input[id$="_value"][id*=' + i + '"]') Commented Oct 20, 2014 at 8:30
  • 1
    Arun has answered your question, but your basic strategy appears to be flawed -- for instance, $('input[id$="_value"][id*="1"]') will match both id 1 and id 11 (or 12, 13, etc.). Commented Oct 20, 2014 at 8:33
  • 1
    Thanks @FrédéricHamidi, I know I just wanted to simplify my question, actually I'm checking if my Id Contains "_i_" not just "i". Commented Oct 20, 2014 at 11:01

1 Answer 1

3

You need to use string concatenation to use the value of variable i - you are trying to find input elements with id ending with _value and has an i in its id

$('input[id$="_value"][id*="' + i + '"]')

But since you can get complete id, you can use the id selector also

$('#something_' + i + '_value')
Sign up to request clarification or add additional context in comments.

2 Comments

because otherwise i will not be recognized as the internal variable i
@arun Can you add a fiddle?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.