When the home ready function is executed, at that time there is no element that matches the ".readless-anchor" selector. The .on() method works, it needs one element to use as a parent. All events that occur in his descendants will bubble to the parent and will call the appropriate handler. That is why it is important that the jquery primary selector already exists.
From the documentation ,
Event handlers are bound only to the currently selected elements; They must exist on the page when your code makes a .on () call.
The second parameter for the .on() function is the selector with which to filter.
In your case, you can bind .on() to the body and filter your classes.
$("body").on("click", ".readmore-anchor", null, showHiddenText); $("body").on("click", ".readless-anchor", null, hideShownText);
This is sorting equivalent to what you could do using .live()
$("body").find(".readmore-anchor").live('click', showHiddenText);
Amith george
source share