Last active
December 23, 2015 02:19
-
-
Save kidchenko/6565843 to your computer and use it in GitHub Desktop.
A função $.detach() remove os elementos do dom preservando todos os dados e eventos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//.detach() removes the list from the DOM, then it can be modified and reinserted into the status element. | |
//.detach() removes an element from the DOM, preserving all data and events. | |
This is useful to minimize DOM insertions with multiple html elements. | |
$('.update-available-flights').on('click', function() { | |
$.getJSON('/flights/late', function(result) { | |
var flightElements = $.map(result, function(flightItem, index){ | |
var flightEl = $('<li>'+flightItem.flightNumber+'-'+flightItem.time+'</li>'); | |
return flightEl; | |
}); | |
$('.flight-times').detach() | |
.html(flightElements) | |
.appendTo('.flights') | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment