jQuery Pass this Element to Function
- Article
- Comment
jQuery Pass this Element to Function. Sometimes, we need to call a custom function with current selected item. we have option to use it here with “jQuery(this)” object. So we have to pass it to another function. we have few methods to pass it to the another functions. Lets take a look at each one.
1.Passing an Element directly :
This one, if we know the ID or Class of an element, we can simply pass it to another function as like the following example
$('div#parent_div_kvcodes').on('click', function() { call_to_another_fn($('#child_id_or_class')); });
2. Call the custom function Directly :
its simpler way to call your custom function on the event triggering function, like this one :
$('div.parent_div_kvcodes').click(my_child_fn_kvcodes);
and for the delegate methods, just use the following method
$('div.main_element').live('click', my_child_fn_kvcodes);
you can write the custom functions separately.
function my_child_fn_kvcodes() { var summa = $(this).val(); //Here its available to use alert(summa); }
And, here its, if you have any doubts, let me help you.