I'm trying to make clicking on a button the content of div
on the side editable. Home
Better viewing the code:
<div id="nome" class="container">
<div class="col-10">
<p class="editar" contenteditable="false">Digite o nome</p>
</div>
<div class="col-2">
<button>Editar</button>
</div>
<div id="Sobrenome" class="container">
<div class="col-10">
<p class="editar" contenteditable="false">Digite o Sobrenome</p>
</div>
<div class="col-2">
<button>Editar</button>
</div>
</div>
</div>
Currently jQuery is like this, but clicking the button selects both the content.
$("button").click(function() {
if ($("div > .editar").attr("contenteditable") == "false") {
$("div > .editar").attr("contenteditable", "true");
$("div > .editar").focus().text("");
$("div > .editar").addClass("selecionado");
$(this).text("Concluído");
} else {
$("div > .editar").attr("contenteditable", "false");
$("div > .editar").blur();
$("div > .editar").removeClass("selecionado");
$(this).text("Editar");
if ($("div > .editar").is(":empty")) {
$("div > .editar").text("Digite o nome");
};
};
});
I'm not finding a way to use the .closest that I think would be a possible save for assigning the clicked button to the div element next to it, since both have the same parent (the #name or #surname).