0
$('.reporte, .maquinaria').on('change', function () {
    var clase = $(this).hasClass('reporte') ? "reporte" : "maquinaria";
    var item = {};

    $(clase).each(function () {
        item[$(this).attr('id')] = $(this).val();
    });
    json[clase].splice(0, 1);
    json[clase].push({
        item
    });
    console.log(json[clase])
});

if I make something like this:

$('.clase').each(function () {
    item[$(this).attr('id')] = $(this).val();
});

it works. But I want to pass the class with the var clase that I already have.

1 Answer 1

2

The class needs a . before it in the selector. $("." + clase)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it worked! i'm new with Jquey and i didn't know that i could made something like that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.