سؤال

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...

هل كانت مفيدة؟

المحلول

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

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

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

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top