私はouterHTMLを変更したいのですが、これが私がしていることです:
$(data.description)[0].outerHTML = $(data.description)[0].outerHTML.replace('red', 'black');
値は次のとおりです。
$(data.description)[0].outerHTML: "<p style="color: red;">desc1</p>"
そしてそれは変わりません。変更方法は?
data.description には次の値があります。
<p style="color: red;">desc1</p><p style="color: red;">desc2</p>
そして、 $(data.description)[0] だけを変更したい。
これが私のコード全体です:
var ingsLines = $(data.description);
for (var i =0; i < ingsLines.length; i++) {
if (someCondition) {
$(data.description).eq(i).css('color', 'black');
}
}
try{$('#myTextarea').html(data.description);}catch(err){}
コードは値を変更し、赤の代わりに黒を置きますが、data.description は赤のままです。