0
jQuery('.pricefield select','.pricefield input').each
    (jQuery(this).change (function (){
        alert(jQuery(this).attr("type")); //it give undefined
        alert(jQuery(this).is(':input')); //it gives false
        var allInputs = jQuery(":input"); 
        alert(allInputs.attr('type'));  //it gives hidden
        get_sum();
    }
));

How can I can identify the field type as select or radio or checkbox?

1
  • That syntax doesn't look right, .each expects a callback but you're passing a jQuery collection. Can you post a demo to reproduce the issue? Commented Jan 11, 2014 at 11:22

2 Answers 2

3
jQuery('select, input', '.pricefield').on('change', function () {
     var tag  = $(this).prop('tagName'); // return "select", "input" etc
     var type = $(this).prop('type'); // return "radio", "checkbox" etc
});

FIDDLE

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

Comments

0

You had some wrong syntax, missing a function declaration inside the each(), but actually you can write it more simple, like:

jQuery('.pricefield select, .pricefield input').change(function () {
    alert(jQuery(this).attr("type"));
    alert(jQuery(this).is(':input')); 
    var allInputs = jQuery(":input");
    alert(allInputs.attr('type'));
    get_sum();
});

Demo

Comments

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.