Skip to content

Instantly share code, notes, and snippets.

@d21anthony
Last active August 29, 2015 13:57
Show Gist options
  • Save d21anthony/9837625 to your computer and use it in GitHub Desktop.
Save d21anthony/9837625 to your computer and use it in GitHub Desktop.
jQuery Tips and Tricks
// Goal - Target a specific div in dom tree remove all other elements within body
Solution 3:
****************************************GOOD
$('.alpha').prependTo('body').nextAll('div').remove();
Fishers Solution:
*************************************** GOOD
$(document).ready( function() {
if ( $('div#lp-content-wraper').length ) {
$('#lp-content-wraper').clone().appendTo( $('body').html('') );
}
});
Solution 1:
***************************************NO GOOD
$('div').not('#allPage').remove();
or
$('div:not(#allPage)').remove();
ref: http://stackoverflow.com/questions/5801114/how-to-remove-all-divs-except-the-first-one-from-body-using-jquery
Solution 2:
****************************************NO GOOD
var a = $('.calendars-beta');
var something = $('.calendars-beta');
$('div').remove(); $(a).appendTo('body');
*Good Article for jQuery vs. Javascript Comparison in syntax*
http://toddmotto.com/is-it-time-to-drop-jquery-essentials-to-learning-javascript-from-a-jquery-background/
*Prepending is helpful*
http://stackoverflow.com/questions/8321093/how-to-put-this-element-to-first-place-using-jquery
*Remove all divs after a certain element*
http://stackoverflow.com/questions/6641365/remove-all-elements-after-certain-element
@d21anthony
Copy link
Author

As always there are many ways to complete task. I'm not really sure which way is best. If anyone someday stumbles upon this, please give your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment