1

How can I attach content to dynamically created tab? if I leave a div with that id there is a mess.

  1. the third tab content apper in the first tab
  2. after I click the checkbox it looks good but in the third click (hide and show again) the third tab content dissaper.

How can I press the checkbox to show and hide the tab and and his content dynamically?

live: http://jsfiddle.net/dSxby/

html:

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">tab 1</a>
        </li>
        <li><a href="#tabs-2">tab 2</a>
        </li>
    </ul>
    <div id="tabs-1">
        <table class="form-table">
            <tr>
                <th scope="row">
                    <label for="dp_add_license">Add tab</label>
                </th>
                <td>
                    <input type="checkbox" id="dp_add_license" name="dp_add_license" value="1"
                    />
                </td>
            </tr>
        </table>
    </div>
    <div id="tabs-2">
        <p>tab  2 content.</p>
    </div>
    <div id="tabs-3">
        <p>tab 3 content.</p>
    </div>
</div>

jquery:

 $(document).ready(function() {
    $("#tabs").tabs();
      $('#dp_add_license').click(function() {
          if ($(this).is(':checked')) {
              $("#tabs").tabs("add", '#tabs-3', "tab 3");
          } else {
              $("#tabs").tabs("remove", '#tabs-3');
          }
      });
});
1
  • 1
    You can use jquery .append function to dynamically add tab. Commented Feb 12, 2013 at 10:21

1 Answer 1

2

Style the id="tabs-3" to display:none;: http://jsfiddle.net/dSxby/1/

<div id="tabs-3" style='display:none;'>
    <p>tab 3 content.</p>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

faster answer...just writing it.
thanks but it doesn;t work with a few more clicks on the checkbox as i sad before tab 3 content dissaper

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.