http://jsfiddle.net/jaspermogg/pFyNY/1/ - you can double click the div to edit, or single click the link to open. That what you wanted?
$('.a0').dblclick(function(e){
e.preventDefault();
$(this).parent().find('input').val($(this).find('a').text()).show().focus();
$(this).hide();
})
$('#url0, #url1').each(
function(index, element){
$(element).blur(function(){
$(this).hide().prev().show().find('a').html(this.value);
})
}
);
And here's a jsFiddle that changes the href of the a
to the value you edited it to, just in case that's what you're trying to do next :-) http://jsfiddle.net/jaspermogg/pFyNY/2/
Here's the jsFiddle that does what you want - http://jsfiddle.net/jaspermogg/pFyNY/5/
JS -
$('.a0 a').click(function(){
var href = $(this).attr('href');
// Redirect only after 500 milliseconds (CHANGE THE 500 IN THE CODE TO DETERMINE HOW LONG THE USER GETS TO DBLCLICK)
if (!$(this).data('timer')) {
$(this).data('timer', setTimeout(function () {
window.location = href;
}, 500));
}
return false; // Prevent default action (redirecting)
});
$('.a0').dblclick(function(){
clearTimeout($(this).find('a').data('timer'));
$(this).find('a').data('timer', null);
$(this).parent().find('input').val($(this).find('a').text()).show().focus();
$(this).hide();
})
$('#url0, #url1').each(
function(index, element){
$(element).blur(function(){
$(this).hide().prev().show().find('a').html(this.value);
})
}
);
Inspired by Jquery create Double Click event on A Href