0

this pattern href="javascript:stop(this); pass the hyperlink object to stop function, but i also want to pass invoked event to that function. how can i do that? my records are getting load through ajax so cant attach .click(function(event){}) with it. and if i attach click on each AJAX call then web slows down on IE6.

please guide me

Thanks

4
  • i want to prevent the default action of link for some reason because on bases of some flag i want to put delay in hyperlink processing Commented Apr 24, 2012 at 7:49
  • 3
    Oh its 2012 year give up with IE6 and 7! Commented Apr 24, 2012 at 7:51
  • If you develop for IE6 to work as fast as modern browsers, I can only hope you're being paid by the hour. Commented Apr 24, 2012 at 7:53
  • any idea how can i send event from hyperlink? on document ready i am binding .click with all <a> but records loaded from ajax are not attached to that click event as the are loaded after document.ready Commented Apr 24, 2012 at 7:53

1 Answer 1

2

You have jQuery so you can use delegates/live events instead of inline events or those nasty javascript: hrefs:

$('#parent').on('click', 'a', function(e) {
    // you can use this and e (the event) here
});

#parent needs to be an element that already exists and will contain the newly added elements. a is the selector to match the elements inside #parent on which you want the click events to trigger. You may use $(document) instead of $('#parent') to resemble .live() from older jQuery versions, but using a parent element that is closer to the inner elements is better for performance reasons.

Sign up to request clarification or add additional context in comments.

3 Comments

browser gives me this error Object doesn't support this property or method on $('#parent').on('click', 'a', function(e) { // you can use this and e (the event) here });
You need to use a recent jQuery version - preferably 1.7.2. If you do not have 1.7, use $('#parent').delegate('a', 'click', function(e) {}); instead (or upgrade to 1.7.2!)
Nice... delegate works for me... .live() also worked for dynamically added list..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.