Learn free online HTML5, javascript, and jquery Tutorials by Examples

Wednesday, 29 October 2014

on click css toggle in jquery

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>change css</title>
<link rel="stylesheet" type="text/css" href="day.css" />
<script src="jquery.js"></script>
<script>
 $(document).ready(function(e) {
  $('button').click(function(e) {
    //var $p = $(this).data('file'); /* using html tag */
    var $p = $(this).text().toLowerCase(); /* simple way */
    console.log($p);
    $(this).siblings('button').removeAttr('disabled').end().attr('disabled','disabled');
             $('link').attr('href', $p + '.css');
    //$(this).attr('disabled','disabled')
        });
    });
</script>
</head>
<body>
 <h1>Hello Content....</h1>
    <button data-file="day">day</button>
    <button data-file="night">night</button>
</body>
</html>

No comments:

Post a Comment