Tell me how to choose a selector with an attribute that contains a variable? For example, there is an input field with a name attribute. The value of the field name value: "inspDate" + singlInspTime[j].id . His view on the html-page will be: name="inspDate1283" .

It is necessary to create a selector of the form: $('input[name="и_что_здесь_будет_с_учетом_переменной_которую_нельзя_взять_в_кавычки???"]').val();

    1 answer 1

    Do not look for it?

     $('input[name="inspDate' + singlInspTime[j].id + '"]').val(); 

    As an example:

     var test = 666; var value = $('input[name="inspDate' + test + '"]').val(); console.log(value); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input name="inspDate666" value="value666" /> <input name="inspDate999" value="value999" /> 

    • it seems, but it does not work - the second square bracket is not wrapped in quotes ... - PrinceOFF
    • @PrinceOFF wat? take a closer look at it again)) Added even a snippet for greater loyalty - Alexey Shimansky
    • Yes, it seems that this is what we need, thank you! - PrinceOFF