Monday, April 11, 2011

What is my problem with tab-selecting in JQuery?

I want to create a webpage in which I can use the JQuey tabs both by a side-bar and by the upper button-bar of the Jquery tabs itself.

My code:

<!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=ISO-8859-1" />
  <title>title here</title>
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript" src="ui.core.js"></script>
  <script type="text/javascript" src="ui.datepicker.js"></script>
  <script type="text/javascript" src="ui.tabs.js"></script>
  <link rel="stylesheet" type="text/css" media="screen" href="local.css" />
  <script type="text/javascript">
    $(document).ready(function(){
    $("#datepicker").datepicker();
    });
  </script>
  <script type="text/javascript">
    $(document).ready(function() {
      $("#tabs").tabs();
    });
    $("select2").click(function() { // bind click event to link
        $("$tabs").tabs("select", 1); // switch to third tab
        return false;
    });
  </script>
</head>
<body>
  <div id="container">
    <div id="row">
      <div id="leftsubcontainer"><div class="column-in">
        <h4>rev0.1</h4>
        <p>medewerkernaam</p>
        <br/>
        <div type="text" id="datepicker"></div>
        <br/><br/>
        <br/><br/>
        <p>log out</p>
        <button id="select2">kies derde</button>
        <br/><br/>
      </div></div>
      <div id="rightsubcontainer"><div class="column-in">
        <div id="tabs">
          <ul>
            <li><a href="#tabs-1">Nunc tincidunt</a></li>
            <li><a href="#tabs-2">Proin dolor</a></li>
            <li><a href="#tabs-3">Aenean lacinia</a></li>
          </ul>
          <div id="tabs-1">
            <p>tekst1</p>
          </div>
          <div id="tabs-2">
            <p>tekst 2</p>
          </div>
          <div id="tabs-3">
            <p>tekst 3</p>
          </div>
        </div>

      </div></div>
    </div>
  </div>
</body>
</html>

The problem is, that, whenever I click on the button, the tabs are not changing (i.e. it does not select the right tab).

Does anyone know what I have been doing wrong?

From stackoverflow
  • You have a problem here :

    $("$tabs").tabs("select", 1);
    

    You should use a # instead of $ :

    $("#tabs").tabs("select", 1);
    

    And passing 1 as second parameter will select second tab, not third.

  • Minor detail but:

        $(document).ready(function(){
        $("#datepicker").datepicker();
        });
        </script>
        <script type="text/javascript">
                $(document).ready(function() {
                        $("#tabs").tabs();
                });
    

    could be merged into:

        $(document).ready(function(){
                      $("#datepicker").datepicker();
                      $("#tabs").tabs();
                });
    

0 comments:

Post a Comment