[ Create Own Event for Jqueryplugin problem ]
Dear all,
I have code blow
My HTML:
- <div id='container'>
- <div class='item' id='itemone'> ... </div>
- <div class='item' id='itemtwo'> ... </div>
- </div>
My Plugin here
- // My Plugin
- (function($){
- $.fn.myplugin = function(options)
- {
- if (this.length > 1){
- this.each(function() {$(this).myplugin (options)});
- return this;
- }
- var elem = $(this);
- var set = $.extend({
- someoption1 : 'option1',
- someoption2 : 'option2',
- myevent:'myevent'
- }, options || {});
- //init here
- {
- elem.children().each(function(){
- //add click event for all child
- $(this).click(function(){
- alert(' Click children ');
- var ID = $(this).attr('id');
- //In here how to put ID in to myevent to use after.
- })
- })
- }
- //------------------------------------------------
- return this;
- };
- })(jQuery);
When i use this plugin.
- $('#container').myplugin ({
- myevent: function(id){
- //Do something with this element_id. Ex: call ajax ...
- alert(id); // Will out put itemone or itemtwo
- }
- });
The code above is just an example in my case. I apply it to more complex projects
My problem is when i click child item i want to output
myevent to do somethings. Please help me !