How to end a jquery function on click

I am currently using the jQuery slug plugin to create a header based project pool. This works great. What I do troube only updates the slug when the user clicks the edit link. Right now, when the edit link is called, the slug function is started, and it works fine, but when the "done" link is clicked, I need to find a way to disable the slug function. I hope this makes sense.

    $('#edit_slug').click(function() {
    //allow user to edit the project slug
    $("#edit_project_name").stringToSlug({  //this is the slug plugin
        getPut: '.project_slug',
        hide: false
    });
    $('input.project_slug').show(); //show the input
    $('input.project_slug').next("span").remove().end(); //remove the span with the slug
    $('#edit_slug').hide(); //hide edit link
    $('input.project_slug').after(" <a href='#' id='done_edit_slug'>Done</a>"); //show done link 
});

//if the user is done editing the slug show the span with the slug in it
$('#done_edit_slug').live('click', function() {
        $("#edit_project_name").stringToSlug().end(); //my attempt to make the function end
        $('input.project_slug').after("<strong><span>"+$('input.project_slug').val()+"</span></strong>"); //show the slug as a span
        $('input.project_slug').hide(); //hide the input box
        $('#done_edit_slug').remove().end(); //remove done link
        $('#edit_slug').show(); //show edit link


});

I am not sure if this is the best way to do this, and I am open to ideas. Most importantly, I do not know how to end the function stringToSlug()when pressed #done_edit_slug.

Thank!

+3
source share
1 answer

.

$('#done_edit_slug').live('click', function() {
        $("#edit_project_name").unbind("keyup keydown blur");
        $('input.project_slug').after("<strong><span>"+$('input.project_slug').val()+"</span></strong>");
        $('input.project_slug').hide();
        $('#done_edit_slug').remove().end(); 
        $('#edit_slug').show();
});

, .

+1

Source: https://habr.com/ru/post/1794983/


All Articles