1

I have a page with a widget in it. There is no cross scripting. I want to use Jquery events to communicate between the two. How can I raise a jquery event on a div in widget and then catch it in widget and do something with it?

Any examples or code snippets would be really helpful.

marcgg
  • 65,020
  • 52
  • 178
  • 231
Priyank
  • 14,231
  • 18
  • 78
  • 107
  • 1
    two what? what widget? can you post an example? – Kobi Dec 29 '09 at 11:19
  • forget about widget. Could you please tell me how can I raise a simple jquery event and then catch it. I think that would suffice. I did some googling and all I found "live", "trigger" and "bind/unbind". But am not clear about what/how they contribute to raising an event and catching it successfully? – Priyank Dec 29 '09 at 11:22

2 Answers2

1

If you can get by with the standard events then this is very simple. You bind an event handler to the div in the widget (assume the div has id="widget") thus:

$('#widget').bind('click', function(e){
    // your code here runs when widget div receives the click event.
    // e is the W3-standard DOM event, in case you need it, but
    // you're free to ignore it
});

then you can trigger that from elsewhere with $('#widget").click(). It would be neat to define custom events to do this but that's a bit more advanced. Once you have the basics working you can google "jquery custom events".

Yatrix
  • 13,361
  • 16
  • 48
  • 78
0

Take a look at this question, even if it's not exactly the same it might help you

Community
  • 1
  • 1
marcgg
  • 65,020
  • 52
  • 178
  • 231