Edit, Updated
Try (v2)
html
<div class="foo">abc123
<br /> <span>def789</span>
<br /> <section>ghi456</section>
</div>
css
.foo{
color: red;/*don't remove*/
}
@media (max-width: 768px){
.foo{
background-color: blue;/*remove*/
font-size: .8em;/*remove*/
}
div{
color: #000;/*don't remove*/
}
}
@media (max-width: 768px){
.foo span{
color: green;/*remove*/
font-size: 36px;/*remove*/
}
.foo section{
color: blue;/*remove*/
font-size: 48px;/*remove*/
}
}
js
Note, .foo{color: red;/*don't remove*/} remains set at .foo children ; possible to set other valid value at properties
$(function() {
if (window.innerWidth <= 768) {
$("style").text(function (_, o) {
return o.replace(/\.foo+\{\n+.*\n+.*\n+\s+\}(?=\n\s+div)/g, "")
});
$(".foo *").each(function (i, el) {
el.style.all = "unset"
})
}
});
jsfiddle http://jsfiddle.net/guest271314/v7LLo7q1/1/
See unset , all
$(function() {
if (window.innerWidth <= 768) {
$("style").text(function (_, o) {
return o.replace(/\.foo+\{\n+.*\n+.*\n+\s+\}(?=\n\s+div)/g, "")
});
$(".foo *").each(function (i, el) {
el.style.all = "unset"
})
}
})
.foo{
color: red;/*don't remove*/
}
@media (max-width: 768px){
.foo{
background-color: blue;/*remove*/
font-size: .8em;/*remove*/
}
div{
color: #000;/*don't remove*/
}
}
@media (max-width: 768px){
.foo span{
color: green;/*remove*/
font-size: 36px;/*remove*/
}
.foo section{
color: blue;/*remove*/
font-size: 48px;/*remove*/
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="foo">abc123
<br /> <span>def789</span>
<br /> <section>ghi456</section>
</div>
window.matchMedia()Start by reading the applied styles during a matched media query and remove them? Here is a read demonstrating similar