troubleshooting Question

remove animation for multiple selection

Avatar of newbie27
newbie27Flag for United Kingdom of Great Britain and Northern Ireland asked on
JavaScriptWeb Development
19 Comments1 Solution474 ViewsLast Modified:
Hello Experts,
I am showing jquery animation using the DIV on onclick event over sinlge element and the same function is been triggered for multiple selection which executes for all the elements available on the page. I wanted to show the animation only when it is been called from invidividual item and not for all.  
Can someone please look into the attached  code and advice me the change I would need.
Your help is much appreciated.
Regards
Sam
PS: Hielo, if you are around please have a look into this.

function addToShortList(){ 
				var myId = $(this).attr('id');
				var theId = myId.replace('_lnk', '');
				var myTitle =  $(this).attr('title') ;
                
				//Don't add the same item again.. [i think that there is a cooler wya to do this]
				var myLi = $('#' + theId + '_li').html();
				if (myLi){
					//this doesn't work on the first click?! we need a better test
					$('#'+myId).mousedown(function(){$('#' + theId + '_li').css('background','#fef8a5')});
					$('#'+myId).mouseup(function(){$('#' + theId + '_li').css('background','')});
                    return;
				}
                
				// create div for the animation
				var spigot = $(this).after('<div id="' + theId + '_spg" style="left:' + $(this).offset().left + '; top:' + $(this).offset().top + '; position: absolute; background:#fef8a5; z-order: 6000; ">' + myTitle + '</div>');
				$('#'+ theId + '_spg').offset((($('#shortlist').offset().top)-110), (($('#shortlist').offset().left)-0), 400);
				$(this).animate({opacity: "0.3"}, 500);
                
				//I.E seems to require display:none; followed by .show/slideDown event. FF is OK without!
				  	
				$('#shortlist').prepend('<li id="' + theId + '_li" title="'+ myTitle +'" style="background-image:url(\'\');padding-left:0"><a href="#" class="dynAdded" onclick="removeItem(this); return false;" title="Remove">&nbsp;[-]</a>' + myTitle + ' </li>');	
 
				
				$('#'+  theId + '_li').slideDown("slow");
				$('#'+ theId + '_spg').fadeOut('fast',  function(){$(this).remove()});				  
                
                 
				//N.B. The page should load the cookie and then set the Add2ShortList buttons to opacity 0.3 - so's you know.. :) use .each fn
				//$.cookie('shortlist', theId+","+myTitle+","); 
				saveShortList(theId+":"+myTitle);
			 
				
				
			}
//=====================
 
// This is how I am calling the above function 
 
$('.addToShortList').click(addToShortList);  // for single element
 
// for all the elements on the page
		$('#addAll').click(
			 			$('.addToShortList').each(addToShortList);
			 	  	);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 19 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros