2

I have a lot of doms with these names:

<input id="partido1-jugada4-empate" name="bets[3][0][0]" title="partido1-jugada4-empate" type="radio" value="X">

<input id="partido1-jugada4-empate" name="bets[3][1][0]" title="partido1-jugada4-empate" type="radio" value="X">

...

<input id="partido1-jugada4-empate" name="bets[3][13][0]" title="partido1-jugada4-empate" type="radio" value="X">

I need select these with something like:

$( "input[name*='[3][*][0]']" )

where previous line give some input with that name

Daniel Garcia Sanchez
  • 2,306
  • 5
  • 21
  • 35
  • 1
    You can't use wildcards in the middle of the class like that, but you could concatenate a variable in there if your JavaScript knows what number is supposed to go there, maybe in a loop? – Starscream1984 Sep 15 '15 at 16:26

2 Answers2

2

As this question here suggests

jQuery selector for matching at start AND end of ID

You should do the following:

$("input[name ^=//[13//]][name $=//[0//]")

So it reads if the name starts with [13] and ends with [0]

The backslashes '//' are used to tell jQuery that '[' and ']' are not it's reserved brackets.

Edit:

The proper answer is thanks to:

ᾠῗᵲᄐᶌ

In the comments below :)

Community
  • 1
  • 1
Vect0rZ
  • 401
  • 2
  • 6
1

You can use .filter() and use a regex to compare the name to see if it matches a certain pattern

var x = $('input').filter(function(i,v){
    return /^bets\[3\]\[.+\]\[0\]$/.test(v.name);   
});

Fiddle

^bets\[3\]\[.+\]\[0\]$

Regular expression visualization

Debuggex Demo

wirey00
  • 33,517
  • 7
  • 54
  • 65