Search code examples
javascriptjqueryjquery-uijquery-ui-resizable

Variable does not work with alsoResize: for colSelect


I got this code, which works fine, until I change '.1' too colselect. I guess its because it gets the value too late and when I want to use colselect it haven't registered. Does anyone have any ideas on how to solve this?

$(document).ready(function() {

        var colSelect;
        
        $('.test2').mousedown( function(){      
            colSelect = '.' + $(this).attr('id');
        });
        
        $( '#1' ).resizable(
        {handles:'e'},
        {alsoResize: '.1'} // <- here I would like too change '.1' to colselect
        );
});

Solution

  • Updated:

    $(document).ready(function() {
    
        var colSelect;
    
       $('#one').on('mouseover' ,mousedwn);
    
     function mousedwn(){
        colSelect = '.' + $(this).attr('id');
        resize(colSelect);
    
     }
    $('#one').on('mouseout' ,function(){
        $('#one').off('mouseover' ,mousedwn); //prevent memory leaks
    });
    
    
     });
    
    function resize(para){
    
     $( '#1' ).resizable(
        {handles:'e'},
        {alsoResize: para} 
        );
    
     }
    

    Working Fiddle