Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Guard animation: only slide down if currently hidden $('#toggle-btn').on('click', function () { if ($('#panel').is(':hidden')) { $('#panel').slideDown(300); } else { $('#panel').slideUp(300); } }); // Check element type in a delegated handler $('#toolbar').on('click', '*', function () { if ($(this).is('button')) { console.log('Button clicked:', $(this).text()); } else if ($(this).is('a')) { console.log('Link clicked:', $(this).attr('href')); } }); // Validate: mark required empty fields $('form input').each(function () { if ($(this).is('[required]') && $(this).val() === '') { $(this).addClass('error'); } });
Result
Open