How can I clear the content without fear, "stop working with this script?" dialogue?

On Windows Forms, there is a BeginUpdate / EndUpdate pair on some controls. I want something similar, but for jQuery.


I have a div that contains a div. eg:

<div id='reportHolder' class='column'>
  <div id='report'> </div>
</div>

Inside the inner div add a bunch (7-12) of pairs of elements a and div, for example:

<h4><a>Heading1</a></h4>
<div> ...content here....</div>

The total size of the content is probably 200 thousand. Each div simply contains a fragment of HTML. Inside it there are many elements <span>containing other html elements, and they nest, possibly at 5-8 levels. Nothing unusual, I don't think. ( UPDATE : using this answer , I found out that there were 139423 elements in the fragment.)

After adding all the content, then I create an accordion. eg:

$('#report').accordion({collapsible:true, active:false});

.

, div, looooooong, 3 4 : " script?"?

:

1:

    $('#report').accordion('destroy');
    $('#report').remove();
    $("#reportHolder").html("<div id='report'> </div>");

2:

    $('#report').accordion('destroy');
    $('#report').html('');
    $("#reportHolder").html("<div id='report'> </div>");

3:

    $('#report').accordion('destroy');
    $("#reportHolder").html("<div id='report'> </div>");

, :

4:

    $('#report').accordion('destroy');
    $('#report').empty();
    $("#reportHolder").html("<div id='report'> </div>");

, .

('destroy'), , . html div.

jQuery 1.3.2.

- .

ps: FF3.5, IE8.


:

  • ?

  • ?


FF, " 4", , :

data()
trigger()
triggerHandler()
add()
each()
each()
add()
empty()
each()
each()
(?)()    // <<-- this is the call to empty()
ResetUi()  // <<-- my code
onclick

, add() . , . , () jQuery - . html, html-, .add(), , .

jQuery HTML dom?

Windows Forms BeginUpdate/EndUpdate . - , jQuery.


:
jquery: DOM?

+3
2

jQuery :

$('#report')[0].innerHTML = '';

, IE (jQuery , , , IE , , ).

+3

, "" ( jQuery 1.4.2):

empty: function() {
  for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
    // Remove element nodes and prevent memory leaks
    if ( elem.nodeType === 1 ) {
      jQuery.cleanData( elem.getElementsByTagName("*") );
    }

    // Remove any remaining nodes
    while ( elem.firstChild ) {
      elem.removeChild( elem.firstChild );
    }
  }

  return this;
},

cleanData: function( elems ) {
  var data, id, cache = jQuery.cache,
      special = jQuery.event.special,
      deleteExpando = jQuery.support.deleteExpando;

  for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
    if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
      continue;
    }

    id = elem[ jQuery.expando ];

    if ( id ) {
      data = cache[ id ];

      if ( data && data.events ) {
        for ( var type in data.events ) {
          if ( special[ type ] ) {
            jQuery.event.remove( elem, type );
          } else {
            removeEvent( elem, type, data.handle );
          }
        }
      }

      if ( deleteExpando ) {
        delete elem[ jQuery.expando ];
      } else if ( elem.removeAttribute ) {
        elem.removeAttribute( jQuery.expando );
      }

      delete cache[ id ];
    }
  }
}

, empty() ( , DOM) cleanData(), node, expando , , , .

, . , , - :

$('#report').children().each(function() {
  var $this = $(this); 
  setTimeout(function() { $this.remove(); }, 0);
});

, 10 #report, 10 , .

+1

Source: https://habr.com/ru/post/1747426/


All Articles