jQuery Pass this Element to Function
X

Congrats, You are Subscribed to Receive Updates.

jQuery Pass this Element to Function


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.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Congrats, You are Subscribed to Receive Updates.

Advertisement

Category Posts