진세훈 진세훈 -4 years ago 110
ASP.NET (C#) Question

asp net get dynanic tag height in javascript

in javascript

this is simple code

function fnInsertTag(tag)
{
tag.children().each(function ()
{
if ([MainTag].height() + $(this).height() >= ([page_height] - 15))
{
if ($(this).prop('tagName').toLowerCase() == 'div')
{
var empty_tag = $(this).clone();
// add tag to [MainTag]
[MainTag].append(empty_tag);
fnInsertTag($(this));
}
}
}
}


i want to add tag in
[MainTag]

it so great, and work well in slow performance computer(or slow condition)

but in nomal condition(or fast condition) code can't get
[MainTag].height()
and
$(this).height()


i don't know why

some time (in slow condition) do well

some time (in nomal,fast condition) don't well


can anyone help me?

Answer Source

Change append tag to complete earlier queued tasks, promise() may be used.

[MainTag].promise().done(
  function() { 
    [MainTag].append(empty_tag);
 });

Refer working js fiddle

Code, I have used to test the problem

function fnInsertTag(tag) 
{
   tag.children().each(function () 
   {


      if (jQuery("#MainTag").height() + $(this).height() >= (page_height - 15)) 
      {
      page_height = jQuery("#MainTag").height() + $(this).height() ;
         if ($(this).prop('tagName').toLowerCase() == 'div')
         {
            var empty_tag = $(this).clone();
            // add tag to [MainTag]
            jQuery("#MainTag").promise().done(
            function() { jQuery("#MainTag").append(empty_tag);});
            fnInsertTag($(this));
         }
      }
   });
   }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download