How to use jQuery events on content loaded via AJAX

I am working on a project, where I have to perform some jQuery/Ajax events on contents loaded via Ajax.
I have search on Google and found a solution which is working for me. I am sharing it with you.

May be it would be helpful for you.


jQuery selectors select matching elements that exist in the DOM when the code is executed, and don't dynamically update. When you call a function, such as .click() to add event handler(s), it only adds them to those elements. When you do an AJAX call, and replace a section of your page, you're removing those elements with the event handlers bound to them and replacing them with new elements. Even if those elements would now match that selector they don't get the event handler bound because the code to do that has already executed.

Event handlers

Specifically for event handlers (i.e. .click()) you can use event delegation to get around this. The basic principle is that you bind an event handler to a static (exists when the page loads, doesn't ever get replaced) element which will contain all of your dynamic (AJAX loaded) content. You can read more about event delegation in the jQuery documentation.

For your click event handler, the updated code would look like this:

$(document).on('click', "#click", function () { 
$('#click').css({       
"background-color": "#f00",        "color": "#fff",        "cursor": "inherit"    
}).text("Open this window again and this message will still be here.");    
return false; 
});

That would bind an event handler to the entire document (so will never get removed until the page unloads), which will react to click events on an element with the id property of click. Ideally you'd use something closer to your dynamic elements in the DOM (perhaps a <div> on your page that is always there and contains all of your page content), since that will improve the efficiency a bit.

Please share on you social sites, if you found it useful.
Thanks
Read More

PlatformIO - Arduino Alternative IDE for IoT integrated platform

PlatformIO - Arduino Alternative IDE for IoT integrated platform:







When developing Arduino sketch,  we all use Arduino IDE, anyway, there are several Arduino alternative IDE. This alternative IDEs are useful and more user-friendly.
Arduino IDE is the first IDE we all use when approaching to Arduino development for the first time. It is simple and provides all the features to write, compile and upload the code to Arduino boards.
Read More

Scientist discovered new form of Light

New way to produce a new form of light. It's attainable by binding light to a single electron by combining both properties.
Read More

Saudi Prince Al - Waleed Talal willing to buy Twitter

Twitter may be acquired by Saudi Prince







Saudi Prince Al - Waleed Talal willing to buy. Twitter has poor economic situation at these day. This microblogging site is decide to rent their San Fransisco headquarter to face that trouble.



But Twitter failed to resolve their economic problem in upcoming time. It may be acquired by Saudi Prince Al - Waleed Talal  and Ballmer.
Read More

How to Modify Nexus Launcher’s Appearance in Nova

How to Modify Nexus Launcher’s Appearance in Nova:



Earlier nowadays the world was treated to a sneak peek at the new Nexus launcherthat is believed to be coming with the 2016 Nexus phones. This new launcher additional a chevron to open the app drawer and a shortcut to Google currently at the top of the homescreen. 







Now due to some incredibly fast work from Corey Zonin anyone will have a really similar experience in Nova!
Read More

Make Badge(Item count) in Android [Tutorial]

Make Badge(Item count) in Android [Tutorial]







In this tutorial we are aiming to see a way to create Badge (Item Count) to a android Application. Badge is really used to show number of notification, message,product count .We can see many android app use Badge to their Application these days. there's no cutoff way to do it we'll do it by coding ourself. during this application we are aiming to see a way to create Badge in Image Button and button.
Read More

Top 3 Mobile Game Based on Pokémon Go

Top 3 Mobile Game Based on Pokémon Go:



As I sit here and watch as millions of people every day download Pokemon Go on their smartphones, it makes me wonder if mobile gaming has evolved form the 2D gaming realm to an augmented reality-enhanced future.



While Pokemon Go is only one game, the implications on the gaming space will be gigantic. Not only will we see an influx of augmented reality-based games which utilize data from the real world. Here are a few predictions I will make for the next 2-3 years based on the extraordinary success of Pokemon Go:
Read More