1
$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    //CODE CODE CODE
});

How can I access the value of box which was set in the previous iteration? Alternatively, is it possible to access it via a key of some kind?

$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    prevsize = $(this).box[/* previous iteration element id or name */].size
    //CODE CODE CODE
}); 

The problem is that I need to know the data associated with each 'input.ISSelectSearch' element box so that I can change them depending on the values of the current or preceding box objects. In other words I need a connection between the element box objects so that I can specify certain changes in one based on the values of another.

2 Answers 2

4

you can do something like this

var pre = null;
$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    //condition so that first time it dosent shows an error
    if(pre!=null){
     //CODE

    }
    pre = this;
    //CODE CODE CODE
}); 

EDIT AFTER THE COMMENT:-
probably you wanna use $.data() method
this was you can associate the data with the element
so inside the loop you can do

$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    $('input.ISSelectSearch').data(i,box);
    //and now you can retrive the data whenevr you want
    var olderObject = $('input.ISSelectSearch').data(SOME_OLDER_INDEX)
});
Sign up to request clarification or add additional context in comments.

3 Comments

Are you sure that you want the condition pre!=null ? On which iteration will it be not null?
I guess you want the pre=thisoutside the if
Ok and if I have 5 elements in each loop and for example I need access 1fst element box object properties from the 3rd element. I don't want to use any global variables like pre. Maybe there is some manipulation methods that could access all stored box objects in memory. I think JS and jquery somehow stores them into the memory or in etc shared storage
0

You can do it with index if you like

var $This = $('input.ISSelectSearch');
$This.each(function (index, value) {
  var Pre;
  var box = { size: 80, width: 110 };
  if (index > 0) {
    Pre = $This[index - 1];
    //Your code hear
  } else {
    //otherwise
  }
});

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.