1

I have an array of objects fetched using jQuery.getJSON(). I want every one of my objects to be represented by HTML div element, so when you click the element you have access to all the properties of corresponding object. What is the best way to do it?

I wanted to do it like this:

$('.mydiv').click(function() {
   var id = $(this).attr('id');
   for (i=0; i<myObjectsArray.length; i++){
     for (x in myObjectsArray[i]){
         //..and here I got confused...
     }  
   }
});

Is this approach any good or is there a better way to do it. Thanks.

1
  • i find it hard to understand your question/suggest some kind of solution without knowing more about the content of myObjectsArray. arranging it so it can be accessed by myObjectsArray[id] i probably a good idea. Commented Feb 15, 2010 at 11:24

1 Answer 1

1

You can store data in the data property of your jQuery object
docs here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.