views:

554

answers:

2

I'm trying to use jQuery UI's .tabs() to obtain content via AJAX, but the default behavior is to grab the entire page's content. How would I obtain content from a specific #id and/or multiple #id's?

I have a feeling I will need to use the load: event (http://docs.jquery.com/UI/Tabs#event-load), but I need an assist figuring this out.

Example:

The Page with the tabs that is getting and displaying the tabbed content. I have placed #content after the first #the_tabs link to retrieve in an attempt to obtain that specific region of the content, but the entire page is still loaded.

<div id="tabs">

    <div id="tabs_display">

    </div>

    <ul id="the_tabs">
     <li><a href="testcontent.html#content" title="tabs display"><span>1</span></a></li>
     <li><a href="testcontent2.html" title="tabs display"><span>2</span></a></li>
     <li><a href="testcontent.html" title="tabs display"><span>3</span></a></li>
     <li><a href="testcontent2.html" title="tabs display"><span>4</span></a></li>
   </ul>

</div><!-- /#tabs -->

The page being retrieved by the previous markup:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
    <head>
     <title>Remote HTML Page Example</title>
    </head>
    <body>
     <div id="content">
      I want this content
     </div>
     <div id="other_stuff">
      Not this content 
     </div>
    </body>
</html>

the JS (for setup purposes):

$(document).ready(function(){

    /* Tabs
    --------------------*/
    $(function() {

     var $tabs = $('#tabs').tabs({

     });

    });

});
A: 

$(document).ready(function(){

/* Tabs
--------------------*/
var $tabs = $('#the_tabs').tabs({
 ajaxOptions: {
  dataFilter: function(data, type){
   return $(data).filter("#content").html();
  }
 }
});

});

Solution props to Supavisah in #jquery on irc.freenode.net

tester
A: 

I seem to be missing something here. The code above generates the tabs and looking at the console it performs a get request and and grabs the whole page, however the tab content doesn't update and it seems this dataFilter isn't working properly. Anyone else get this to work? Seems like there should be a simple way to filter the ajax content to a specific div and not display the entire page like how .load(URL, " #content"); works. Thanks in advance.

sgd