I need to catch some elements in a form. The elements look like this:
<div id="wpforms-22603-field_17-container" class="wpforms-field wpforms-field-likert_scale" data-field-id="17">
<div id="wpforms-22603-field_18-container" class="wpforms-field wpforms-field-likert_scale" data-field-id="18">
<div id="wpforms-22603-field_19-container" class="wpforms-field wpforms-field-likert_scale" data-field-id="19">
The variable part is the number after -field_
and of course the data-field-id
value itself.
So I wrote this:
var elem = $(this).closest('[id^=wpforms-'+this_form_id+'-field_][id$=-container]');
where this_form_id
contains the value 22603
. This works well, but I need to also specify a class in the matching process, and that class is wpforms-field-likert_scale
.
So I tried this:
var elem = $(this).closest('[id^=wpforms-'+this_form_id+'-field_][id$=-container] .wpforms-field-likert_scale');
which doesn’t work. What am I doing wrong?
2
Answers
Remove the space before the
.
Alternatively use filter
You can chain multiple finds with
.end()