passing $(this) from function to function

后端 未结 3 533
旧时难觅i
旧时难觅i 2021-01-23 12:01

I have 2 different event on different classes :

$(\'.box1\').click(function(){
$(this).find(\'something\').css(\'red\')
}

$(\'#otherId .box2\').change(function(         


        
3条回答
  •  余生分开走
    2021-01-23 12:36

    You can use something like this to pass it through if you want to get an inputs value then change it and output the final value next to it:

    var finalOutput;
    
    function getDetails(args) {
        args = "Hello World";
        return args;
    }
    
    $('.box2').change(function(){
        var inputValue = $(this).val();
        finalOutput = getDetails(inputValue);
    
        $('.box2').after('' + finalOutput + '');
    });
    

    Here is a working example:

    http://jsfiddle.net/La4v9mL0/

提交回复
热议问题