Search code examples
javascriptjqueryjquery-uijquery-ui-dialogjquery-ui-tabs

jQuery UI tabs and dialog


How do you add jQuery ui tabs to a dialog box on click? Here is my code.

<p>
  <a href="#" class = "premium_payer">Premium Payer:</a> 
  <span data-bind = "text: movements_owner_fullname"  id = "movements_payer_fullname" >         </span>
</p>

<script type="text/javascript">
  $('a.premium_payer').click(function payerDialog(e){
    $("#premium_payer").html('').dialog();
    $("#premium_payer").append('<p>' + "Full name: " + payer_fullname + '</p>').dialog();
    $("#premium_ayer").append('<p>' + "ID Number: " + person_id + '</p>').dialog();
            e.preventDefault();
    });
</script>

Solution

  • <script type="text/javascript">
        $(document).ready(function(){
            $('a.premium_payer').click(function payerDialog(e){
                e.preventDefault();               
                var tabs = $("<div><ul><li><a href='#tab1'>tab1</a></li><li><a href='#tab2'>tab2</a></li></ul><div id='tab1'>Tab1 content</div><div id='tab2'>tab2 content</div></div>");
                 $("#premium_payer").empty().append(tabs);
                 $("#premium_payer").dialog();
                 tabs.tabs();
            });
        });
    </script>
    

    EDIT if you want an existing element, hide this element with display: none.

     <div id="tabs" style="display:none">
          <ul>
                 <li>
                       <a href='#tab1'>tab1</a>
                  </li>
                  <li>
                        <a href='#tab2'>tab2</a>
                  </li>
          </ul>
          <div id='tab1'>Tab1 content</div>
          <div id='tab2'>tab2 content</div>
     </div>
    
    <script type="text/javascript">
        $(document).ready(function(){
            $('a.premium_payer').click(function payerDialog(e){
                e.preventDefault();               
                var tabs = $("#tabs");
                 $("#premium_payer").empty().append(tabs);
                 $("#premium_payer").dialog();
                 tabs.show();
                 tabs.tabs();
            });
        });
    </script>