Setting watch expression in Firebug: ReferenceError - s undefined

I am trying to figure out how to use firebug to debug my Javascript. Therefore, I have the HTML below. And I want to set the watch expression to var 's'. I went to the Script Firebug tab and opened the Clock panel and entered s in the area labeled “ New clock expression ”.

I get an error message:

ReferenceError: s is not defined

Why?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
.StateOne .InitiallyHidden { display: none; }
.StateTwo .InitiallyVisible { display: none; }
</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
    $(document).ready(function()
    {

        $('.x').click(function() {
               var s = $("#StateContainer")[0];
               s.className = (s.className == 'StateOne' ? 'StateTwo' : 'StateOne');
        });

    });
</script>





</head>

<body>

<button class="x">Change StateContainer</button>

<div class="StateOne" id="StateContainer">
   <div class="InitiallyVisible">Visible first</div>
   <div class="InitiallyHidden">Visible second</div>
   <div class="InitiallyVisible">Visible first</div>
   <div class="InitiallyHidden">Visible second</div>
   <div class="InitiallyVisible">Visible first</div>
   <div class="InitiallyHidden">Visible second</div>
   <div class="InitiallyVisible">Visible first</div>
   <div class="InitiallyHidden">Visible second</div>
</div>



</body>
</html>
+3
source share
1 answer

's' 'x', ​​ . , "s" .

, , 's' , $(document).ready(), :

<script language="javascript" type="text/javascript">
    var s;
    $(document).ready(function()
    {

        $('.x').click(function() {
               s = $("#StateContainer")[0];
               s.className = (s.className == 'StateOne' ? 'StateTwo' : 'StateOne');
        });

    });
</script>
+6

Source: https://habr.com/ru/post/1712381/


All Articles