jQuery/JavaScript equivalent of each() for a single element? -
can tell me how update following code first item that's returned in object (data)? know using each() 1 item isn't efficient , improve it.
$(data).each(function(num, entry){ if ( num > 1 ) return false; });
here's example of data
is:
[ { "id": 1, "title": "my post", "permalink":"http:\/\/site.com\/page.html\/", "date":" 2011-05-10 } ]
update 2:
as data
array (i assume json parsed (if not can use jquery.parsejson
or json.parse
)), can first element simple array access:
var first = data[0];
old answer:
try
$(data).first() // returns jquery object // or $(data).eq(0) // returns jquery object // or $(data).get(0) // returns dom object // or $(data)[0] // returns dom object
depending on data have , want do.
update:
if data
javascript object, there no need pass jquery (jquery working dom).
just loop on
for(var prop in data) { }
but cannot "first" property because unordered.
if array, use data[0]
.
to more, should post data
is.
Comments
Post a Comment