We help IT Professionals succeed at work.
Get Started

Setting a variable in an index loop over jQuery tabs.

brianmfalls asked
Last Modified: 2012-08-13
So...  all conditions are met in the code below.  The 'setting abort placement' alert executes, then the abort displaying the definition of the variable executes.  When the loop ends, the alert outside of the loop displays 'not set'.  Why!?!?!?!  It's maddening.  Shouldn't the second and third alert show the same value???  What am I missing?  TIA!  :)

var abortPlacement = 'not set';

$("#ajaxContainer .ui-droppable").each(function() { // loop through all droppable areas
	var dropContainerID = '#' + this.id; // this is the ID of the container being indexed in the loop, which will be compared to droppableAreaID 
	var containerContent = $(dropContainerID).formhtml();  // this is the content of the container being indexed in the loop
	if (containerContent.indexOf('detailpage') >= 1) { // if coupon exists in content of container being indexed
		alert('setting abort placement');
		var abortPlacement = dropContainerID;
		alert('abortPlacement 1: ' + abortPlacement);

alert('abortPlacement 2: ' + abortPlacement);

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE