2

Just a quick jquery question. I have a form with a number of form-groups in it. I need to iterate over the form-groups, and find a particular element in each one. The form-groups consist of 4 input/select elements, each with a different name:

dialog.find(".form-group").each((index) => {
console.log($(this).find("input[name='active']"));
    if ($(this).find("input[name='active']").checked) {
        console.log("FOO");
    }
})

dialog definitely exists, and it can certainly find form-group objects, but running .find("input[name='active'].val()") consistently returns undefined.

Alex
  • 2,270
  • 3
  • 33
  • 65
  • What specifically are you trying to locate with this `.val()` inside the selector? – Yom T. Feb 01 '19 at 00:51
  • Sorry @jom, I've removed the val(), it was a mistake. The issue persists, though. – Alex Feb 01 '19 at 00:52
  • So which particular element are you finding, ones that have "active" as name and are checked? – Yom T. Feb 01 '19 at 00:53
  • Yes, it should find an input element with the name 'active' within each of the form-groups. It should then run an if statement on those elements. (There is only one element with the name 'active' in each form-group) – Alex Feb 01 '19 at 00:55
  • Might be the same issue like I pointed out [here](/a/54427438/3634538) on another post. – Yom T. Feb 01 '19 at 00:58
  • So when you do `this` inside of this arrow function `.each()`, it's actually referring to the parent element instead of really "each" of the individual `form-group`s. – Yom T. Feb 01 '19 at 01:00
  • That seems to be it, yes. Thank you. If you put it as an answer, I'll accept it – Alex Feb 01 '19 at 01:01
  • Add a snippet to your question with some markup – Adrian Brand Feb 01 '19 at 01:43

0 Answers0