Quick JQuery-question: How can one decide which of two objects comes first in a code?
Edit: I want to do something like this.
var active = $("#second");
if(active is before $("#first")) ...
else ...
Ex:
<table>
<tr>
<td></td>
<td id="first"> </td>
<td> </td>
</tr>
</table>
<table>
<tr>
<td id="second"> </td>
<td>开发者_JAVA百科; </td>
<td> </td>
</tr>
</table>
If you're using jQuery 1.4+, .add()
will do the trick.
As of jQuery 1.4 the results from .add() will always be returned in document order (rather than a simple concatenation).
Reference: http://api.jquery.com/add/
You can write a simple plugin for this:
$.fn.isBefore = function (selector) {
return this.add(selector)[0] == this[0];
};
Then use it like so:
if (active.isBefore("#first")) {...}
// "#first" can really be replaced with any valid expression that can be used
// by $().
Use the first selector
$('table td:first');
See: http://api.jquery.com/first-selector/
Have a look at :first
try this...
$('table td').eq(0);
精彩评论