JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<div id="Test">
<!-- @media only all and (min-width:400px)
<a href="https://twitter.com/TwitterMedia" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @TwitterMedia</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
-->
</div>
JavaScript
/*
* Project: jQuery Media Comments
* Description: jQuery pluggin to add media query functionality to HTML comments
* Author: Steve Podmore (https://twitter.com/StevenPodmore)
* License:
*/
;(function ( $, window, document, undefined ) {
var
mediacomments = "mediacomments",
defaults = {
timeout: 500 //milliseconds to watch for window changes
};
function Plugin( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = mediacomments;
this.init();
};
Plugin.prototype = {
init: function() {
var $this = this;
if(!$($this.element).attr('id')){
$($this.element).attr('id',this.randString(10))
}
var wait = false;
$(window).resize(function(){
if(wait !== false){
clearTimeout(wait);
}
wait = setTimeout(function(){
$this.doQuery($this.element, $this.options);
}, $this.options.timeout);
});
$(window).trigger('resize');
},
doQuery: function(el,opts){
var $this = this;
var els = $(el)
var nodes = this.getComments(els.get(0));
$(nodes).each(function(i,e){
var mq = this.nodeValue.match(/[^\r\n]+/g)[0];
if(mq.match(/@media/g)){
var mql = window.matchMedia($.trim(mq.replace(/@media/g,'')))
var exists = $('#mc' + $($this.element).attr('id') + i).length==0;
if(mql.matches && exists){
var html = $.parseHTML(this.nodeValue.replace(mq,''));
$(html).attr('id','mc' + $($this.element).attr('id') + i).insertAfter(this);
}
if(!mql.matches){
$('#mc' +...