2

So I have a submenu that loads content when a main nav button is hovered over. And while that content is loading I want to display a loading graphic.

The problem is I can't get both functions working together.

1st function - load submenu content (page.php)

2nd function - when page.php is loaded, hide loading graphic

<script>
function functionOne() {
jQuery.get('page.php', function(data) { jQuery('.class').html(data); })
}

function functionTwo() {
  jQuery("#loading").hide();    
};

jQuery(".dropdownhover").one('mouseenter', functionOne.done( functionTwo ););
</script>

<a class="dropdownhover">Button</a>
<div id="loading"></div>

With the above code, neither function works. If I call just the first function like this: jQuery(".dropdownhover").one('mouseenter', functionOne ); that works fine. But I of course need to call both, one after the other. Am I just writing the last line of the script wrong?

0

1 Answer 1

1

As per your requirement, the syntax that you have used is completely wrong, there is no such function done available in Function's prototype.

You can achieve that by just writing,

function functionOne() {
 jQuery.get('page.php', function(data) { 
   jQuery('.class').html(data); 
   functionTwo(); 
 });
}

function functionTwo() {
  jQuery("#loading").hide();    
};

jQuery(".dropdownhover").one('mouseenter', functionOne);
Sign up to request clarification or add additional context in comments.

3 Comments

@SLePort It was OP's code and OP didn't complain anything like, event is triggering for a single time. So I guess that the code was intentional.
Well that was a lot easier than I thought. This works great thank you. And yes the .one was intentional, just need it once.
@user1610904 Glad to help! :)

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.