how to access array in jquery -
the array :
[[object { button={...}}, object { input={...}}, object { checkbox={...}}, object { textarea={...}}], [object { textarea={...}}] ]
in curly brackets have set properties color,value,type etc.
want each object of array , check through properties type of object , call function perform further things. in php use :
foreach($a $b){ // , here .. };
kindly me through , hope can understand trying say.
// var counter page numbers function pagination(i) { alert(i); i--; //page array var result = page; //console.log(result[i]); var $currentelem; $(result[i]).each(function() { currentelem = $(this); console.log(currentelem); }); }
.each
used when you're looping on elements of jquery collection. loop on contents of array or object. use $.each()
:
$.each(result[i], function(n, currentelem) { console.log(currentelem); });
and shouldn't use $(this)
unless this
dom element. if it's javascript object, wrapping in jquery object unnecessary.
you can access properties using normal javascript variable.propertyname
syntax, e.g. currentelem.button
, currentelem.button.color
. append elements view, can like:
var button = currentelem.button; $("<button>", { value: button.value, name: button.name, css: { color: button.color, width: button.width, backgroundcolor: button.backgroundcolor } }).appendto($("#buttondiv");
Comments
Post a Comment