Home > Article > Web Front-end > How to Replace jQuery Class Toggling with Pure JavaScript?
Pure JavaScript Alternative for jQuery Class Toggling
Problem:
Converting a jQuery code that toggles class names for a responsive menu to pure JavaScript.
Solution:
Option 1:
<code class="javascript">var menu = document.querySelector('.menu'); menu.classList.toggle('hidden-phone');</code>
Option 2 (Older Browsers):
<code class="javascript">// Install classList.js using your preferred package manager. var menu = document.querySelector('.menu'); menu.classList.toggle('hidden-phone');</code>
Additional Note:
The above is the detailed content of How to Replace jQuery Class Toggling with Pure JavaScript?. For more information, please follow other related articles on the PHP Chinese website!