I need to determine which element comes first in my markup, such as an input or select. For example
<body>
<input type="text" />
<select><option>Test</option></select>
<body>
In this case, the input comes first in the DOM whereas
<body>
<select><option>Test</option></select>
<input type="text" />
<body>
in this case, select comes first. Any way to do this using jQuery? Thanks
EDIT: Just to clarify, I don’t want the very first element, I ONLY want to know if between the input and select element, which comes first. There could be other elements before the select and input elements.
Use index.
if
$('select:first').index() < $('input:first').index()then theselectis firstSee a sample here: http://jsfiddle.net/ZLmMB/