CSS JavaScript Style Sheet Disabled

HTML link (stylesheet) disabled attribute

You can use JavaScript's removeAttribute method for that.

<html>
<head>
<link id="first_style" rel="stylesheet" href="#" disabled />

<script type="text/javascript">
window.onload = function()
{
document.getElementById('first_style').removeAttribute('disabled');
}
</script>
</head>
<body>
<p>something</p>
</body>
</html>

How to use a different CSS stylesheet if a user has JavaScript disabled in their browser?

Two ways to do it:

  1. Append the JavaScript-only stylesheets with JavaScript:

    function appendStyle(url) {
    var sheet = document.createElement("link");
    sheet.setAttribute("href", url);
    sheet.setAttribute("rel", "stylesheet");
    sheet.setAttribute("type", "text/css");
    document.head.appendChild(sheet);
    }
  2. If you don't mind loading the CSS for the JS and you just want to override your site's default appearance you can use a noscript tag instead:

    <noscript>
    <link href="your/no-js/stylesheet.here.css" type="text/css" rel="stylesheet">
    </noscript>

css javascript style sheet disabled?

You can disable styles by setting the disabled property on the element that loaded them (either a style element for inline styles, or a link element for linked stylesheets). When disabled, a stylesheet's rules aren't applied.

Example:

CSS:

<style id='style2'>
p {
color: green;
font-weight: bold;
}
</style>

HTML:

<p id ='theParagraph'>Click this paragraph to toggle the <tt>style2</tt> styles.</p>

(I know, I know, tt is deprecated.)

JavaScript:

document.getElementById('theParagraph').onclick = function() {
var style = document.getElementById('style2');
style.disabled = !style.disabled;
};

Live copy

How could I turn off a stylesheet?

You can do it server side when the user clicks on a "special" link, your server side code simply "skips" the stylesheets elements.

enable disable stylesheet using javascript in chrome

I was able to get this to work with setting the disabled property and by including a 'title' attribute the stylesheets.
title property makes the stylesheet PREFERRED rather than PERSISTENT. see http://www.alistapart.com/articles/alternate/

How to disable a STYLE element in HTML/JS?

You can enable/disable a style element, using the media attribute.

By setting it to a value that will not match any device, you are actually disabling it.

<style media="max-width: 1px">
/* Nothing contained in this styles element will be applied */
</style>

By dynamically setting and removing this attribute and its value, you can emulate the enabled/disabled behavior, as in the following example:

document.getElementById('but').addEventListener('click', function toggle(){  let styleEl = document.getElementById('styles')  // toggle enabled/disabled  if(styleEl.hasAttribute('media')) styleEl.removeAttribute('media')  else styleEl.setAttribute('media', "max-width: 1px")})
<style id="styles" media="max-width: 1px">   div { color: red }</style>
<div id="but">Click me</div>

Enable and disable css file dynamically using javascript?

Is posible enable and disable css stylesheet with javascript. A example: http://plnkr.co/0exLXB

function del_style() {
document.getElementById("styles").disabled=true;
}

function add_style() {
document.getElementById("styles").disabled=false;
}

I think you could adapt the code for your site



Related Topics



Leave a reply



Submit