3

I want to chain Jquery animations and for the sake of readability I'd like to keep my code "vertical" not "horizontal".

Here's what I've done but does not work:

async function close(id){
    return $(id).slideUp().promise();
}

async function shrink(id){
    return $(id).animate({width: '50%'}).promise();
}

[...]

function update(){
    await close("#myDiv");
    await shrink("#myDiv");
    doSomething();
}

But I get an error: Syntax Error: await is only valid in async functions [...]

I know I can chain Jquery animations (foo().bar()) or use these functions' callbacks but my question really is about async/await

ted
  • 11,582
  • 6
  • 55
  • 96

0 Answers0