
Enable click event on appended element using jQuery
Created at 19-Aug-2021 ,
By samar
Enable click event on appended element using jQuery
In this session, we are going to try to solve the "Enable click event on appended element using jQuery" puzzle by using the computer language.
Click event has an issue on an appended element in jQuery. After appending the html element click event did not work on it. You can use $(document).on('click', '#anchor', function(e) { to enable click event on appended element in jQuery.-
JQuery call on click function on appended anchor element
<!-- HTMLÂ --> <button type="button" id="addAnchorBtn"> Add Anchor element </button> <div id="element"></div> <!-- JQuery CDN with javascript code --> <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> <script> $('#addAnchorBtn').on('click', function(){ html = '<a id="anchor" href="javascript:void(0)"> Anchor </a>'; $('#element').append(html); }); $(document).on('click', '#anchor', function(e) { alert('anchor clicked'); console.log(e); }); </script>
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Jquery
- Show loading icon on click submit button in jQuery
- How to pass javascript variable to laravel route on ajax call
- How to reset form input element on click
- Uncaught TypeError: $.ajax is not a function
- How to preview image before uploading in jQuery
- Execute function after Ajax call is complete
- How to validate input type file size in jQuery for multiple records
- How to check ajax request is completed in jQuery
- Add and remove input fields on click button using jQuery
- Show and hide target element on click button using javascript/jquery
- Mixed Content: The page at 'https://w3codegenerator.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint
- Get the href link on click anchor in javascript
- How to remove Choose File button in jquery
- How to check object is empty or not in jQuery
- Append method to add text to body not working
- Ajax for multiple form
- JQuery find text and show as bold in html page
- Ajax done fail ajaxcomplete in not a function
- (index):128 Uncaught TypeError: MobileNumberVal.test is not a function
- How to get closest form input value in jQuery
- Preview image in BLOB URL format on choose file in jQuery
- JQuery append html to below the target element
- How to use and purpose of localstorage in javascript
- Jquery.validate.min.js:4 Uncaught TypeError: Cannot read properties of undefined (reading 'mode')
- How to find closest upper element and append html to below it in jquery