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

1
  • 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? Commented Sep 15, 2015 at 16:26

2 Answers 2

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 :)

4
  • 1
    Nice answer - Some reason I had a mind block on how to structure it just using a selector
    – wirey00
    Commented Sep 15, 2015 at 16:31
  • hi thanks for answer... but I'm obtaining an error with syntax expression Commented Sep 15, 2015 at 17:33
  • 2
    @DanielGarciaSanchez the correct selector syntax is $('input[name^="bets[3]["][name$="][0]"]')
    – wirey00
    Commented Sep 15, 2015 at 18:21
  • thanks @ᾠῗᵲᄐᶌ it's very very awesome, it worked for me! Commented Sep 16, 2015 at 7:11
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

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.