Last active
August 29, 2015 13:57
-
-
Save d21anthony/9837625 to your computer and use it in GitHub Desktop.
jQuery Tips and Tricks
This file contains 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
// 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.