Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery fire event for element's child

I create jquery custom function.

I want fire event on selector sibling or child like this:

$.fn.CustomFunction = function() {
    $(this).siblings("div").click(function(){
        alert();
    });

    // OR

    $(this + " > div").click(function(){
        alert();
    });
};

But it not work.

How i do this work?


1 Answers

You could try this:

$.fn.CustomFunction = function() {
    $(this).on('click', 'div', function(){
        alert();
    });
);

It binds a click event on the selector div inside this.
More info: http://api.jquery.com/on/

like image 158
LinkinTED Avatar answered Apr 24 '26 21:04

LinkinTED



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!