<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<style>
.content + .content > .item > .copy-this {
color: yellow;
background: black;
}
.random-div {
color: brown;
}
.ruler {
position:fixed;
bottom:20px;
left:0;
width: 600px;
background:blue;
height:5px;
border: 1px dashed gold;
}
</style>
</head>
<body>
<div class="content">
<div class="item">
<div class="copy-this">Some info 1[#1]</div>
<div class="random-div">Not to copy 1[#1]</div>
</div>
<div class="item">
<div class="copy-this">Some info 2[#1]</div>
</div>
<div class="item">
<div class="copy-this">Some info 3[#1]</div>
<div class="random-div">Not to copy 2[#1]</div>
</div>
<div class="item">
<div class="copy-this">Some info 4[#1]</div>
</div>
</div>
<div class="content">
<div class="item">
</div>
<div class="item">
<div class="random-div">This is original content[#2]</div>
</div>
<div class="item">
</div>
<div class="item">
</div>
</div>
<hr class='ruler'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
/* Create a MediaQueryList with matchMedia() method.
| Add a MediaQueryListener and handler.
| Invoke handler and pass MediaQueryList.
*/
var mql = window.matchMedia("(min-width: 600px)");
mql.addListener(viewportObserver);
viewportObserver(mql);
/* Given a MediaQueryList...
| ...use the .matches property to...
| ...determine the viewport size...
| ...If viewport is 600px or more...
| ...remove all cloned content...
| ...otherwise, clone content...
| ...and add it to the destination.
*/
function viewportObserver(MediaQueryList) {
var target = $('.content + .content > .item').eq(idx);
if(MediaQueryList.matches) {
target.each(function(idx, obj) {
$(this).remove('.copy-this');
});
}
else {
$('.copy-this').each(function(idx, obj) {
var clone = $(this).clone(true, true);
target.prepend(clone);
});
}
}
/* If for whatever reason the mediaQueryListener...
| ...is no longer needed, use...
*/// mql.removeListener(viewportObserver);
</script>
</body>
</html>
// Code goes here
/* Styles go here */