Home >Web Front-end >JS Tutorial >jquery animate mutiple dom elements at same time
This quick guide demonstrates how to use jQuery's multiple selectors to simultaneously animate multiple DOM elements. Remember that jQuery's animate()
function is asynchronous, meaning it can execute concurrently on multiple elements.
Refer to the jQuery API documentation for multiple selectors: https://www.php.cn/link/845ce31b9cf79c9aad515d0209881a3c
The Multiple Selector syntax is: ("selector1, selector2, selectorN")
Incorrect Syntax:
<code class="language-javascript">// This will NOT work correctly $('#content', '#sidebar-grab').animate({ /* animation properties */ });</code>
Correct Syntax:
<code class="language-javascript">// This will work as intended $('#content, #sidebar-grab').animate({ /* animation properties */ });</code>
The key difference is the comma (,
) separating the selectors within the jQuery selector string. Using a comma correctly allows jQuery to target and animate #content
and #sidebar-grab
at the same time.
The above is the detailed content of jquery animate mutiple dom elements at same time. For more information, please follow other related articles on the PHP Chinese website!