0
I’m trying to make sure that by clicking a button, the contents of div
next door is editable.
Better visualizing 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 when clicking the button both contents are selected.
$("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 it. Closest which I think would be a possible salvation to assign the button clicked to the div element next to it, since both have the same parent (the #name or #surname).
Hmm, very good idea! But I intend to separate into large groups for future changes and need to keep a button for each input(in case).
– user86267