开发者

Problem resizing DIV after editing innerHtml

开发者 https://www.devze.com 2022-12-17 10:15 出处:网络
I have a problem resizing a DIV, after I make some edit to the innerHtml, <div id=\'resizeme\'>Hello ....(some hidden html elements for re size event)</div&g开发者_如何学Ct;

I have a problem resizing a DIV, after I make some edit to the innerHtml,

<div id='resizeme'>Hello ....(some hidden html elements for re size event)</div&g开发者_如何学Ct;

When I edit the text the resize event isn't firing. I'm using jQuery.


You should see what's happening in your console. when an element is resizable a lot of inner elements will be added to it. if you change the innerHTML of the element those elements added for resizability also lost. so resize will not work. try like below.

$('.editme').keypress(function(){
    var targetid = event.target.id;
        var txt = $('#addTxtBox1').val();
        var temptxt = $('#temptxt').val(); //take hidden txt value which is reside in div
        $('#temptxt').val(txt); //assign edited value again in hidden variable

        var tempselection = $(this);
        $(tempselection).resizable("destroy"); // remove the resizability from the element

        var temphtml = $(tempselection).html().replace(temptxt,txt);


        $(tempselection).html(temphtml);

      $(tempselection).resizable(); // add the resizability again

});
0

精彩评论

暂无评论...
验证码 换一张
取 消