English 中文(简体)
Get element from selector given an index with jQuery
原标题:
var items = $(".myClass");

The code above returns a number of items when used to select all elements. How can I select a specific element, for example the second one? Neither items(2) nor items[2] works.

最佳回答

Try this:

items.eq(2) // gets the third element as a jQuery object (zero-based index)

Source: http://docs.jquery.com/Traversing/eq#index

问题回答

arrays are zero based so you need items[1] for the second one

2nd item would be items[ 1 ] in your case. Also the code you ve provided works perfectly for me (with items[ 1 ]).

try

var items = $(".myClass"); alert($(items)[1]);





相关问题
adding an index to sql server

I have a query that gets run often. its a dynmaic sql query because the sort by changes. SELECT userID, ROW_NUMBER(OVER created) as rownumber from users where divisionID = @divisionID and ...

Linq to SQL nvarchar problem

I have discovered a huge performance problem in Linq to SQL. When selecting from a table using strings, the parameters passed to sql server are always nvarchar, even when the sql table is a varchar. ...

TableView oval button for Index/counts

Can someone help me create an index/count button for a UITableView, like this one? iTunes http://img.skitch.com/20091107-nwyci84114dxg76wshqwgtauwn.preview.jpg Is there an Apple example, or other ...

Move or copy an entity to another kind

Is there a way to move an entity to another kind in appengine. Say you have a kind defines, and you want to keep a record of deleted entities of that kind. But you want to separate the storage of ...

热门标签