- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to bind jQuery events within dynamic content returned via Ajax?
To bind jQuery events within dynamic content, use event delegation. You can try to run the following code to learn how to bind jQuery events within dynamic content returned via Ajax:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(".loadingAjax").on("click", function() { event.preventDefault(); var url = $(this).attr("href"), appendedContainer = $(".append"); $.ajax({ url: url, type : 'get', complete : function( qXHR, textStatus ) { if (textStatus === 'success') { var data = qXHR.responseText appendedContainer.hide(); appendedContainer.append("<a href='#' class='link'>Hi</a>"); appendedContainer.fadeIn(); } } }); }); $(document).on("click", '.link', function(event) { alert("Link clicked!"); }); }); </script> <style type="text/css"> a.test { font-weight: bold; } body { font-family: sans-serif;} </style> </head> <body> <a class="loadingAjax" href="https://www.qries.com"> Click to load Ajax</a> <div class="append"></div> </body> </html>
- Related Articles
- How to bind jQuery events on elements generated through other events?
- What are jQuery AJAX Events?
- How to bind events on dynamically created elements using jQuery?
- How to bind multiple events with one "bind" in Tkinter?
- How can I bind all events on a DOM element using jQuery?
- How to bind events to Tkinter Canvas items?
- How to handle jQuery AJAX error?
- How to handle jQuery AJAX success event?
- How to send button value to PHP backend via POST using ajax?
- How to fire jQuery events with setTimeout?
- How to store and reproduce jQuery events?
- How to implement custom events in jQuery?
- What is the difference between Ajax and jQuery-Ajax methods in jQuery?
- How to handle HTML5 media events using jQuery?
- How we can prioritize jQuery events?

Advertisements