I want to create a hover similar to the example here in the jQuery. But the link is dynamically generated so I'm really having a hard time figuring this out.
I tried this:
$(document).ready( function() {
$('a.g-tabs').on('hover', 'a', function() {
$( this ).append( $('<i class="icon-clear-remove" onClick="tabRemove();"></i>') );
},
function() {
$( this ).find( ".icon-clear-remove:last" ).remove();
});
});
But its not working. Seems like my selector is the problem. How can I select it properly?
UPDATE:
This JS is handles for the view to not refresh if the tab is created:
$(document).on('submit','#pop-form', function(e) {
// make an ajax request
$.post('../admin/FLT_add_tab.do',
$('#pop-form').serialize(),
function( data ) {
// if data from the database is empty string
if( $.trim( data ).length != 0 ) {
// hide popover
$('#popover').popover('hide');
//append new tab and new tab content
var id = $(".nav-tabs").children().length - 1;
$('#popover').closest('li').before('<li><a href="#tab_'+ id +'" data-toggle="tab" class="g-tabs">' + data + '</a></li>');
$('.tab-content').append('<div class="tab-pane" id="tab_' + id + '"> <c:import url="flt-pis.html"></c:import> </div>');
} else {
// error handling later here
}
}
);
e.preventDefault();
});
Not this one is the HTML that handles the tabs if the user goes to this page in first hand:
<!-- Other tabs from the database -->
<c:forEach var="tabNames" items="${ allTabs }">
<li><a href="#" data-toggle="tab" class="g-tabs"> ${ tabNames.key }</a></li>
</c:forEach>
<!-- Add new tab -->
<li><a href="#" id="popover">New <i class="icon-plus-sign"></i></a></li>
As requested the server side code:
@ResponseBody
@RequestMapping( value = "/admin/FLT_add_tab", method = RequestMethod.POST )
public String createNewTab( @RequestParam
String newTab, HttpServletRequest request )
{
HttpSession session = request.getSession();
String returnVal = Credentials.checkSession( session );
if( returnVal != null )
{
return returnVal;
}
String tabName = null;
try
{
DataSource dataSource = DatabaseCommunication.getInstance().getDataSource();
QuestionnaireDAO qDAO = new QuestionnaireDAO( dataSource );
if( qDAO.getTabName( 0, newTab ) == null )
{
qDAO.insertQtab( newTab );
tabName = newTab;
}
}
catch( Exception e )
{
// no logger yet
e.printStackTrace();
}
return tabName;
}