Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/09/2011, 14:58
bigwhite
 
Fecha de Ingreso: agosto-2009
Mensajes: 247
Antigüedad: 14 años, 9 meses
Puntos: 10
Respuesta: Iterar arreglo con jQuery

Bueno...amigo, para empezar tienes dos tipos de each():

http://api.jquery.com/jQuery.each/
http://api.jquery.com/each//

Para iterar sobre una variable (no un selector),... seria el primero

Cita:
<!DOCTYPE html>
<html>
<head>
<style>
div { color:blue; }
div#five { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
<div id="five"></div>
<script>
var arr = [ "one", "two", "three", "four", "five" ];
var obj = { one:1, two:2, three:3, four:4, five:5 };

jQuery.each(arr, function() {
$("#" + this).text("Mine is " + this + ".");
return (this != "three"); // will stop running after "three"
});

jQuery.each(obj, function(i, val) {
$("#" + i).append(document.createTextNode(" - " + val));
});
</script>

</body>
</html>
__________________
The best powerful search engine for MSN messenger profiles I know is msn profile viewer. It's really good either if you have an e-mail address or not. Try it!