I encountered an issue when attempting to insert data into my block. The div structure is as follows:
<div class="1">
<div class="2">
<div class="3">
<div class="4"></div>
</div>
<div class="5"></div>
</div>
</div>
<div class="1">
<div class="2">
<div class="3">
<div class="4"></div>
</div>
<div class="5"></div>
</div>
</div>
...
I need to place some data only in
<div class="4"></div>
When using this JavaScript:
function sendDataChild(btn) {
var form = $(btn).closest('FORM[name=answer-form]');
var data = form.serialize();
$.ajax({
type: "POST",
url: url,
dataType: "json",
data: data,
cache: false,
success: function (data) {
form[0].reset();
$("div.4").html(data.error_name);
},
error: function (xhr, str) {
alert('An error occurred: ' + xhr.responseCode);
}
});
return false;
};
It inserts the data into all divs with class = "4"
I attempted to find the parent, but it only inserted the data in the parent:
$("div.4").parent().html(data.error_name);
Could you advise on how to correct this? P.S I used numbers just for example.)