0

hi when i click on option of the list i want add new tab which is have dynamic content. content get by given href url.

<script type="text/javascript" src="http://www.jankoatwarpspeed.com/wp-content/uploads/examples/dynamic_tabs/jquery-1.4.min.js" ></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#documents a").click(function() {
            addTab($(this));
        });

        $('#tabs a.tab').live('click', function() {
            // Get the tab name
            var contentname = $(this).attr("id") + "_content";

            // hide all other tabs
            $("#content p").hide();
            $("#tabs li").removeClass("current");

            // show current tab
            $("#" + contentname).show();
            $(this).parent().addClass("current");
        });

        $('#tabs a.remove').live('click', function() {
            // Get the tab name
            var tabid = $(this).parent().find(".tab").attr("id");

            // remove tab and related content
            var contentname = tabid + "_content";
            $("#" + contentname).remove();
            $(this).parent().remove();

            // if there is no current tab and if there are still tabs left, show the first one
            if ($("#tabs li.current").length == 0 && $("#tabs li").length > 0) {

                // find the first tab    
                var firsttab = $("#tabs li:first-child");
                firsttab.addClass("current");

                // get its link name and show related content
                var firsttabid = $(firsttab).find("a.tab").attr("id");
                $("#" + firsttabid + "_content").show();
            }
        });
    });
    function addTab(link) {
        // If tab already exist in the list, return
        if ($("#" + $(link).attr("rel")).length != 0)
            return;

        // hide other tabs
        $("#tabs li").removeClass("current");
        $("#content p").hide();

        // add new tab and related content
        $("#tabs").append("<li class='current'><a class='tab' id='" +
            $(link).attr("rel") + "' href='#'>" + $(link).html() + 
            "</a><a href='#' class='remove'>x</a></li>");

        $("#content").append("<p id='" + $(link).attr("rel") + "_content'>" + 
            $(link).attr("href") + "</p>");

        // set the newly added tab as current
        $("#" + $(link).attr("rel") + "_content").show();
    }
</script>

this is my html code

<div id="main">
<div id="doclist">
    <h2>Documents</h2>
    <ul id="documents">
        <li><a href="#" rel="Document1" title="This is the content of Document1">Document1</a></li>
        <li><a href="http://www.dynamicdrive.com" rel="Document2" title="This is the content of Document2">Document2</a></li>
        <li><a href="http://www.dynamicdrive.com" rel="Document3" title="This is the content of Document3">Document3</a></li>
        <li><a href="http://www.dynamicdrive.com" rel="Document4" title="This is the content of Document4">Document4</a></li>
        <li><a href="http://www.dynamicdrive.com" rel="Document5" title="This is the content of Document5">Document5</a></li>
    </ul>
</div>
<div id="wrapper">
    <ul id="tabs">
        <!-- Tabs go here -->
    </ul>
    <div id="content">
        <!-- Tab content goes here -->
    </div>
</div>
</div>
<div id="Document1" style="display:none;">anvdsanvidsnvsidvnsdovnsdoivnsdovsdovnsovsvsmvpsmvlksdvsmdkvmsdkvmsvsd</div>

it's working but i don't want like this. i want display content which i mention in href. please help me how can i do it.

2
  • have you considered using ajax to fetch the dynamic content from the url? Commented Apr 4, 2013 at 13:05
  • 1
    yep. but my main intention i want display the data which i mention url data. not only dis way if u suggest any new to get result like dis Commented Apr 4, 2013 at 13:15

1 Answer 1

1

It basically depends on what type of data you are receiving from the url on what kind of request. Assuming that you simply want to display a HTML page you can append an iframe as follows.

HTML

<div class="dynamic_content">
    <ul class='url_list'>
        <li><a href='#' data="http://www.example.com">Load Example</a></li>
    </ul>
</div>

jQuery

$(document).ready(function(){
    $('ul.url_list > li > a').click(function(){
        var me = $(this);
        var url = me.attr('data'); 
        $('.dynamic_content > iframe').remove();
        $('.dynamic_content').append('<iframe src="' + url + '" width="100%" height="300px"></iframe>');
    });
});

Also, please note i have not tested the above code. It's something just from the top of my mind so you might need to test it.

Update:

Ok, I have updated and tested the code. Also, here is a working example (JSFiddle)

Update:

Here is an updated JSFiddle

Sign up to request clarification or add additional context in comments.

5 Comments

i tested nw only but it's not coming.
@munji_rkt: Ok, I have updated and tested the code. Please check the updated answer. Also, at the end you can have look at a working example.
yep, thank lot Amyth, it's working fine. link just check dis. i don'w want again again reloading. when i click first time dat time only have to loading and going be separate task. dose list option have dispaly in bottom of the frame when i click juery it's showing jquery content. when i click example it's showing the example.com content. i have to put dose option in bottom of the frame. like windows tasks.. thanks Amyth...
amyth see this. can we display like dis. see there is tabs how working. i want display tabs like dat in bottom of the frame.
please check dis where i did mistake tabs

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.