0

I have the following jquery function

$(function(){

  $('.buttonEffectWrapper a').not('#browse-all a').hover(function(){

    pauseResume();
    var imageBrowserContent = $('#mainImageBrowser').html();
    $('#mainImageBrowserTabButtonWrapper, #slideshow > div')
      .animate({opacity:"0"}, {duration:250});

    ajaxFunction('footer');
    alert(imageBrowserContent);

  },
  function(){
    alert(imageBrowserContent);
  })

} );

On mouseover, I copy the contents of #mainImageBrowser to variable imageBrowserContent It then does an Ajax function which replaces the html content of #mainImageBrowser and then alerts me of what the contents are. All of that works.

My intent was to then replace #mainImageBrowser with the original contents, which would be stored in imageBrowserContent. I couldn't get this to work, so I put alert(imageBrowserContent); and no alert every pops up. What am I missing? If I put a text string in the alert, it popups fine, so I am confused...

0

1 Answer 1

3

After reformatting, the problem shows. imageBrowserContent is a local variable of the first function. It will not be visible inside the second function. If you move the variable declaration to the parent function, it will work.

$(function(){
    var imageBrowserContent;
    $('.buttonEffectWrapper a').not('#browse-all a').hover(function(){
        pauseResume();
        imageBrowserContent = $('#mainImageBrowser').html();

        $('#mainImageBrowserTabButtonWrapper, #slideshow > div')
            .animate({opacity:"0"}, {duration:250});
        ajaxFunction('footer');
        alert(imageBrowserContent);
    },
    function(){
        alert(imageBrowserContent);
    })
});
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.