Reputation: 14387
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.
Upvotes: 1
Views: 1190
Reputation:
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".
Upvotes: 1
Reputation: 66525
Take a look at this question, even if it's not exactly the same it might help you
Upvotes: 0