Reputation: 12820
I have created a little div .form_single_input_field
which contains multiple .form_single_input_field
s, whose respective text I would like to log. However, the alert will output all values concatenated together, while I would like to have an array of values. How do I achieve that ?
$(".form_single_input_field").keyup(function () {
var actualTarget = $(this).parent();
alert(actualTarget.find('.form_single_selection_option').text());
});
I know that there is the .each()
function, but this:
$(".form_single_input_field").keyup(function () {
var actualTarget = $(this).parent();
$('.form_single_selection_option').each(function(){
alert($(this).text());
});
});
would alert all values from ALL .form_single_selection_option
s in my document, whereas I would like to have only the children and children's children of the selected/current field.
Upvotes: 0
Views: 45
Reputation: 3079
Change your code to:
$(".form_single_input_field").keyup(function () {
var actualTarget = $(this).parent();
$('.form_single_selection_option', actualTarget).each(function(){
alert($(this).text());
});
});
Upvotes: 2