screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Check if Element is a div</title> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> </head> <body> <h3>Jquery Check Clicked Element is Div or Not</h3> <div id="myDiv">This is a div</div> <h4 id="myHeading">This is a Heading</h4> <p id="myParagraph">This is a paragraph</p> <script> $(document).ready(function () { // Click event handler $(document).on('click', function (event) { // Check if the clicked element is a div if ($(event.target).is('div')) { alert('Clicked element is a div.'); } else { alert('Clicked element is not a div.'); } }); }); </script> </body> </html>