jQuery UI Tabs and wp_enqueue_script
-
I’m trying to use some jQuery Tabs in my sidebar as per this website.
If I call the jQuery script in my header.php like this first example it works fine:
<link type="text/css" href="https://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" /> <script type="text/javascript" src="https://jqueryui.com/latest/jquery-1.3.2.js"></script> <script type="text/javascript" src="https://jqueryui.com/latest/ui/ui.core.js"></script> <script type="text/javascript" src="https://jqueryui.com/latest/ui/ui.tabs.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#tabs").tabs(); }); </script> <?php wp_head(); ?>
But if I call it like this (which is the supposed proper way) then it doesn’t work. The .js files seem to get loaded into the head, but the tabbed content just displays inline. Is there something different between the WP jQuery files and those from jQuery’s site?
<link type="text/css" href="https://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" /> <?php wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-tabs'); ?> <script type="text/javascript"> $(document).ready(function(){ $("#tabs").tabs(); }); </script> <?php wp_head(); ?>
If anyone is curious to the HTML that goes with this, here it is:
<div id="tabs"> <ul> <li><a href="#fragment-1"><span>Shoutbox</span></a></li> <li><a href="#fragment-2"><span>Latest Comments</span></a></li> <li><a href="#fragment-3"><span>Poll Jam</span></a></li> </ul> <div id="fragment-1"> Shoutbox goes here. <div>If you can see this it works with DIVS</div> </div> <div id="fragment-2"> Latest Comments go here. </div> <div id="fragment-3"> Polls Go here. </div> </div>
Thanks for the help!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘jQuery UI Tabs and wp_enqueue_script’ is closed to new replies.