LoginSignup
6
6

More than 5 years have passed since last update.

jQueryでnoscriptを実装するためのお作法

Posted at

自分のブログの過去記事からの転載ですが。

example.html
<html>
<head>
<style type="text/css">
.jsenabled {
    font-weight:bold;
    border: 2px solid #0000ff;
    padding: 5px;
    width: 400px;
    display: none;
}
.jsdisabled {
    font-weight:bold;
    border: 2px solid #ff0000;
    padding: 5px;
    width: 400px;
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script>
    $(document).ready(function() {
    $(".jsenabled").show();
    $(".jsdisabled").hide();
})
</script>
</head>
<body>
    <div class="jsenabled">JavaScript is enabled</div>
    <div class="jsdisabled">JavaScript is disabled</div>
</body>
</html>

CSSでJavaScriptが有効なときに見せたい領域を非表示(display: none)にしておき、JavaScriptが有効な場合のみjQueryで表示に切り替えるというやり方です。

6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6