I'm trying to use jQuery (version 1.4+) to determine the specific type of an input element on a form. I've already seen how to determine the element type using jQuery, as described in these Questions:
Get element type with jQuery finding the type of an element using jQuery How to find element type in JQuery
...using script similar to this:
var btn_submit = $(calendar_box).find('input[name="submit"]');
var elementType = btn_submit.prop('tagName');
This does work. However, my question is a bit more specific. I have a check_form function that enables the Submit button only when the required fields are filled out; if the submit button is a standard form button, it removes the "disabled" attribute, and if the button is an image, it swaps in an "enabled" version of the image. The problem is that for either type of button, elementType always comes back as INPUT. I need to be able to distinguish between the two kinds of input so that I can take the proper action with respect to enabling the button.
Is there a way to use jQuery to find the subtype of an element? Seems to me that elementType will be INPUT regardless of whether I'm examining a textbox, a button, or an image.
edit
Sorry about leaving out the HTML.
For the HTML button case, it looks like:
<input type="button" id="submit" name="submit" value="COMPUTE CALENDAR" onkeypress="return handle_key_press_box(event);" onclick="submit_form();" disabled="disabled" />
I've also used an image like this:
<input type="image" id="submit" name="submit" onkeypress="return handle_key_press_box(event);" onclick="submit_form();" disabled="disabled" />
...and like this...
<a href="javascript:submit_form();"><img src="../images/favicon.ico" onkeypress="return handle_key_press_box(event);" /></a>
When I use the link approach, I get 'null' for the elementType value. I suppose I can use this in my function logic, but it seems less than optimal, somehow.
Thanks in advance.
edit
That works, Ejay. attr('type') still returns null for an anchor tag, but it does distinguish properly between image and button types. I'm marking this as Answered!