Add a class to a specific browser:
Google Chrome
<script type="text/javascript">
if (navigator.userAgent.toLowerCase().match('chrome') && document.getElementById('content'))
document.getElementById('content').className = document.getElementById('content').className + " chrome";
</script>
2. Show/Hide
<script>
function showHide () {
document.getElementById('hideIt').style.display = "none";
document.getElementById('showIt').style.display = "inherit";
}
</script>
3. =============================
easily checks at run time if the user's browser width is 800px or more:
=============================
var mql = window.matchMedia("screen and (min-width: 800px)");
if (mql.matches){ // if media query matches
console.log("Window is 800px or wider");
}
else{
console.log("not");
}
JQuery to hide a page completely before it goes live in production:
<script type="text/javascript">
$(document).ready(function () {
$('body').hide();
if (window.location.href.indexOf("test=true") > -1) {
$('body').css('display', 'block');
});
}
</script>
2. JQuery after loading code updates for a specific page
$(document).ready(function () {
$('#Mobile').find('.cBig:last').addClass('noSeparator');
$('#Mobile .pmms .btn-sml-buynow').addClass('blue');
$('#Mobile .pmmsios .btn-sml-buynow').addClass('blue');
$('#Mobile .pmms .btn-sml-buynow span').text('Free');
$('#Mobile .pmmsios .btn-sml-buynow span').html('<%=m_GTMVersion%>');
$('#Mobile .pmms .btn-sml-buynow').val('Free');
$('#Mobile .pmms .btn-sml-buynow').attr('title', 'Free');
$('#Mobile .pmmsios .btn-sml-buynow').val('Free');
$('#Mobile .pmmsios .btn-sml-buynow').attr('title', 'Free');
});
3. JQuery toggle (Hide/Show)
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").toggle();
});
});
</script>