0

How can I add jQuery click events to a page which was loaded with XMLHttpRequest?

1 Answer 1

1

Use the $.live() method to handle items that will appear later in the pages lifetime.

  $("a").live("click", function(e) {
    e.preventDefault(); // disables all links, even links added via AJAX
  });
Sign up to request clarification or add additional context in comments.

6 Comments

could you guid me something about $.live
but how can i combine and external function to $.live() with adding any event suppose i have a function like function myfnc(){ alert("Done"); } than how can i combine this to $.live on window load......
You should keep your functions out of your external pages. Keep your javascript in javascript files, html in html files, php in php files, and so on :)
i am using elastic() jquery plugin to make my textarea behaves auto height......i am implement it liek $(document).ready(function(){ $("#textarea").elastic(); }); where #textarea is id of my textarea....so how can i implement this in $.live()
$.live() only works for a limit set of events: click, doubleclick, mousedown, etc. For this reason, you won't be using $.live() to apply $.elastic() to your textareas. Instead, you'll have to manually apply it after each ajax-request finishes. Look for new textareas, and apply it to them.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.