JSFiddle - React, Tailwind, and code Playground

HTML

<div>when clicked on the div it should be displayed on textbox and it should be editable on edit button what should be the ajax code i have done this with php but want to do this with ajax
<input type="text" name="edit" value="edit">

</div>

CSS

div {
    margin: 20px 0;
}

textarea {
    width: 100%;
}

JavaScript

function divClicked() {
    var divHtml = $(this).html();
    var editableText = $("<textarea />");
    editableText.val(divHtml);
    $(this).replaceWith(editableText);
    editableText.focus();
    // setup the blur event for this new textarea
    editableText.blur(editableTextBlurred);
}

function editableTextBlurred() {
    var html = $(this).val();
    var viewableText = $("<div>");
    viewableText.html(html);
    $(this).replaceWith(viewableText);
    // setup the click event for this new div
    viewableText.click(divClicked);
}

$(document).ready(function() {
    $("div").click(divClicked);
});