King Julien
King Julien

Reputation: 11308

Edit links in place

I use this javascript to edit text in place: http://josephscott.org/code/javascript/jquery-edit-in-place now I need to edit links as well. But when I click on link instead of just making it editable I'm redirected to the link address. How can I change it so that if double click a link just make it editable and don't redirect anywhere?

Can anyone please help?

Upvotes: 1

Views: 406

Answers (3)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196002

use the dblclick event and the preventDefault method

  $('a_selector').eip( "save.php", {
    form_type: "textarea"
} );

$('a_selector').dblclick(function(e){
  e.preventDefault();
})

update After toying around with the plugin a little..

I believe it natively allows to set the event which starts the edit..

$('a').eip( 'save.php', {
        form_type  : 'textarea',
        edit_event : 'dblclick'
    } );

but i am not sure they correctly handle the case where the target element is a link, as i do not see in their code any attempt to stop the default behaviour ..

Maybe you could modify the source code and add it yourself ..

Upvotes: 3

jasongetsdown
jasongetsdown

Reputation: 1305

Return false from your event handler, or with jQuery use e.preventDefault() in the handler, where e is the event object.

Upvotes: 0

Austin Fitzpatrick
Austin Fitzpatrick

Reputation: 7359

You'll need to override the default link behavior, then trigger the edit-in-place code.

$("a").click(function(){
    //whatever you have to call to make it editable
    return false; //prevent the link from being followed
});

Upvotes: 1

Related Questions