I have an array with different elements inside it. Like array contain input elements and select elements. I want to check for particular type. I tried this but it didn’t work
var mandotaryElementsArray = $('.mandotary');
$.each(mandotaryElementsArray, function(index, element){
if (element == input) {
var $inputElement = $(this);
var test1;
} else if (element == select) {
var $selectElement = $(this);
var test2;
}
}); //end of .each()
Actually i want to check something that is similar to instance of in Java. Here i want to check if element is type of input then do this, if element is type of select then do this, if element is type of radiobutton then do this.. How can i make this check here?
Thanks
You can use either the
.tagNameproperty (which always returns uppercase for HTML):Or, you can use jQuery’s
.is():Even better would probably be to let the selector do all the work for you and just select the items you want for a particular operation and operate on the desired selector like this: