jQuery + CSS. How do I compute height and width of innerHTML?

有些话、适合烂在心里 提交于 2019-12-04 15:02:10

Change this:

"height" : childDivObject.height() + "px"

to this:

"height" : childDiv.height() + "px"

Looks like you are trying to get the height of the content rather than the div itself.

Got it. Because jQuery toggles the css display property to hide/show the popup.

The answer is to do this:

    parentDivObject.css({
        "left": left + "px",
        "top" : top  + "px"
    }).show();

    parentDivObject.css({
        "height": childDivObject.height() + "px"
    });

I set the height after the jQuery show() method which toggles display and then height becomes valid. It's not pretty, but it works. Cheers.

George Katsanos

Normally you would use a callback, but html() doesn't have one, but there's something else, called promise.

jquery html() callback function http://digitizor.com/2013/08/03/jquery-html-callback-function-using-promise/

   $('#divId').html(someText).promise().done(function(){
        //your callback logic / code here
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!