I need to create a tabbed page where the user can click a tab / button to duplicate the last tab as shown in the image below:

In this case, you'd click the plus sign and TAB 3 would be created with the same contents as TAB 2.
I'm wondering what would be the best way to go about this?
Edit:
Here's a JSFiddle (be sure to hit run first) with the code I've so far. It's almost there, but if your tab name has a space it doesn't dupe the last child html for some reason.
It is better to manually generate
idrather than directly using the user input to generateid, since it should be unique, it can not contain spaces etc.We can set the tab's title to user input while generating unique
idbehind the scene.I've updated your code by making use of jquery
clone()method as shown below:Side note: I've given a common class name for the content
<div>'s to easily get theidlike$(".tab").last().attr("id"), rather than getting it from the tabs which will look something like$("#tabs").find("li:last").prev().find("a").attr("href")P.S: Looks like jquery ui keeps on attempting to fetch the content even if
#is specified for the tab's anchor. I've given it theidof dialog instead to satisfy the poor thing.