Question

How can I determine the index of an <input> element inside the form...

Why do I want to do this?

It'll help me give error codes in the backend and using the error code, I can use JQuery to automatically update the error message beneath the form <input> field using <small> tag (used for errors in zurb-foundation) and make same code scalable to all pages.

Obviously, I'll design error codes in the backend according to the place value in question...

Was it helpful?

Solution

Use selector1.index(selector2), e.g.

$('#myform input').index($('#myinput'))

Fiddle: http://jsfiddle.net/7K22B/

API doc: http://api.jquery.com/index/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top