Monthly Archives: Oct 2018

Adding tabbed panels to Bootstrap – No jQuery

A great little piece of functionality built into Bootstrap is the ability to clear up some screen space using panels cascaded behind each other in tabs.  The best part is, it’s super easy to implement.

Here’s the code:

<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
    <li class="active"><a href="#tab1" data-toggle="tab">Tab 1</a></li>
    <li><a href="#tab2" data-toggle="tab">Tab 2</a></li>
    <li><a href="#tab3" data-toggle="tab">Tab 3</a></li>
    <li><a href="#tab4" data-toggle="tab">Tab 4</a></li>
    <li><a href="#tab5" data-toggle="tab">Tab 5</a></li>
<div id="my-tab-content" class="tab-content">
    <div class="tab-pane active" id="tab1">
        <h1>Tab 1</h1>
    <div class="tab-pane" id="tab2">
        <h1>Tab 2</h1>
    <div class="tab-pane" id="tab3">
        <h1>Tab 3</h1>
    <div class="tab-pane" id="tab4">
        <h1>Tab 4</h1>
    <div class="tab-pane" id="tab5">
        <h1>Tab 5</h1>

The above code will leave you something looking like this:


Feel free to use, copy and modify this code as you need to.

Share this post:
read more

Getting the ID of draggable and droppable elements – jQuery

jQuery’s drag and drop functionality is fantastic and adds excellent interactivity to your web application.  However, it can be a little confusing, so here are some straightforward examples that should get you off to a flying start when venturing into the world of drag and drop.

First, we need a few things to move around, so let’s create some:

<div id="div_01" class="draggable">Div 01</div>
<div id="div_02" class="draggable">Div 02</div>
<div id="div_03" class="draggable">Div 03</div>
<div id="div_04" class="draggable">Div 04</div>
<div id="div_05" class="draggable">Div 05</div>

You’ll need to get these in the context of your web page.

Next, we need somewhere to drop them:

<div id="dropzone_1" class="dropzone" style="height:100px;width:100px;border:1px solid black"></div>
<div id="dropzone_2" class="dropzone" style="height:100px;width:100px;border:1px solid black"></div>
<div id="dropzone_3" class="dropzone" style="height:100px;width:100px;border:1px solid black"></div>

I’ve used inline styles in the example above in case you are copying and pasting into a test HTML page of your own.  Inline styling isn’t great in a production environment; a separate style sheet is always better.  I’ve also assumed, that you have loaded the jQuery / jQuery UI version[s] of your choice onto the page by this point as well.

Making these elements draggable and droppable is easy.  Just add a function that covers both scenarios and then build upon them.

$(function () {

At this point, you should be able to grab you divs and move them around the page.  They won’t do anything aside from move around the page, but it’s quite a novelty the first time it happens successfully!

It’s at this point the language used by jQuery can be a little bit confusing.  “Draggable” is obvious; it is something that can be dragged around the screen, its when you get to “droppable” that people sometimes run into confusion.  “Droppable” suggests you are dealing with something that once you start dragging around, is then available to be dropped, however, this isn’t the case.  “Droppable” by jQuery’s definition is the area that you drop a draggable.  The draggable itself, contains the drop event, whereas the droppable is just a static place your draggable gets dropped.

Confused yet? Don’t be; it’s effortless when you see it broken down.

Doing something with my draggable and droppable.

Take a look at this extended version of the code snippet above.  What you see below is taken directly from one of my live projects, so will need to be customised to suit your project:

$(function () {
                function (event, ui) {
                    $(this).css("z-index", 10);
        drop: function (event, ui) {

            const dropZoneID = $(this).attr('id');
            const droppedItemID = ui.draggable.attr("id");

             Do something with your newly gathered information

So what is going on in the code above?  Let’s start with the draggable.  There are various events associated with the draggable.  Notably, these are start, stop and drag.  In the example above I’ve used the start event to bring the item, I’m dragging to a z-index of 10.  With my Bootstrap projects, I’ve found this handy to ensure the thing I’m dragging around remains at the top.  If I don’t set this index with Bootstrap, the draggable can end up going behind some of the other elements.

You can find a full reference to jQuery draggable here.

Lovely, but the exciting part comes when you drop these draggable.

The two critical pieces of information you need when dealing with draggable items and dropzones [and this may seem obvious] are, what you’ve dropped and where you’ve dropped it.  This is achieved using the “drop” event inside the droppable.  Here, I have created two constants [variables are also fine] that will gather this information.

A great way to visualise this if you are starting out with these is to add a test div, so you can see what’s happening.

Create a div, like this:

<div id="testDropDiv"></div>

Then in your code, add the following:

        drop: function (event, ui) {

            const dropZoneID = $(this).attr('id');
            const droppedItemID = ui.draggable.attr("id");

                     .append("I've just dropped div with ID: " + droppedItemID + " Onto: " + dropZoneID);


Which should then update each time you drop one of your draggable onto a dropzone.

The reference for jQuery droppable is available here.

I hope that gives a little bit of an insight into jQuery’s draggable and droppable.  This short introduction has only just scratched the surface of what is achievable.  I would recommend you have a look at the jQuery UI website to see some more examples.

Share this post:
read more

Recipe Review: The Pioneer Woman; Kicked-Up Tater Tot Hotdish


I really enjoy watching The Pioneer Woman on the Food Network.  Good wholesome food that is easy to make.  For most home cooks, not interested in gourmet cooking, this is a dream come true.

For those of you that have no idea what I’m talking about; Ree Drummond, aka The Pioneer Woman, is an American TV celebrity chef, based out on a ranch in America. Ree’s emphasis is on good quality, simple food that is both easy to cook and to eat.  There are quite literally hundreds of recipes on her site (see link at the bottom), including starters, mains, desserts and sharing platers.  Ree’s website contains something for everybody.

Over the years I have tried dozens of her recipes and loved every single one of them.  So why the sudden review?  Well, I ventured into the realms of the hotdish (Americanism for a casserole for those that are wondering), and for the first time, I was disappointed.

Now, let’s be clear, this has nothing to do with the recipe.  The ingredients and the method are flawless.  What it does highlight, is the distinct difference in pallets between the UK and American citizens.  Reason; The sheer amount of cheese deployed in this savory dish.  I made the Kicked-Up Tater Tot hotdish, and there is cheese everywhere.  Cheese in the meat and cheese at the top.  When you combine this with the milk, sour cream and butter, it all starts to get sickly.

Perhaps it is just my palate, but my advice would be, if you don’t go for extremely sickly savory dishes, then avoid this one.

That said, this is only my opinion of one dish.  Ree’s food is fantastic, and I would recommend anyone, and everyone, try her recipes.

As a side note:

I did love the idea of using the tater tots (which are like potato croquet if you are British) atop a meal and then baked, so I modified the concept slightly.  Having not been able to eat the Ree version, I remade it using a thick Bolognese at the bottom, then covered with the potato, then added a topping of grated cheese.  I baked the whole thing in the oven for 35 minutes and then crisped the top off under the grill.  The potato croquet made an excellent substitute for the spaghetti carbs in a spaghetti bolognese, and the whole dish was very delicious.  I served it with a side of homemade garlic ciabatta.



The Pioneer Woman Website

Kicked-Up Tater Tot hotdish- The Recipe

Share this post:
read more