Created
October 14, 2017 00:02
-
-
Save matt-daniel-brown/33985b4cfc0942ffac5a5c13fe486525 to your computer and use it in GitHub Desktop.
Simple DOM Manipulations Using jQuery.
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
<!DOCTYPE html> | |
<title>My Example</title> | |
<style> | |
.box { | |
background: orange; | |
color: white; | |
width: 150px; | |
padding: 20px; | |
margin: 10px; | |
} | |
</style> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script> | |
$( function() { | |
$( "button" ).click( function() { | |
$(this).after( "<div class='box'>New box</div>" ); | |
}); | |
}); | |
</script> | |
<button>Create a box</button> |
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
<!DOCTYPE html> | |
<title>My Example</title> | |
<style> | |
.box { | |
background: orange; | |
color: white; | |
width: 150px; | |
padding: 20px; | |
margin: 10px; | |
} | |
</style> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script> | |
$( function() { | |
$( "button" ).click( function() { | |
$( "<p>Surprise!</p>" ).appendTo( ".box" ); | |
}); | |
}); | |
</script> | |
<button>Add Content</button> | |
<div class="box"> | |
<p>Main content.</p> | |
</div> |
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
<!DOCTYPE html> | |
<title>My Example</title> | |
<style> | |
div { | |
color: white; | |
padding: 10px; | |
margin: 20px; | |
} | |
.file { | |
background: limegreen; | |
} | |
.folder { | |
background: gold; | |
} | |
</style> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script> | |
$( function() { | |
$( ".file" ).click( function() { | |
$( this ).clone().prependTo( ".folder" ); | |
}); | |
}); | |
</script> | |
<div class="file"> | |
File | |
</div> | |
<div class="folder"> | |
Folder | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment