Answer the question
In order to leave comments, you need to log in
How to insert html code into textNode.textContent?
Good evening!
I get a text node from some tag, and replace its content by overriding the textContent property . The process of getting a text node is implemented in jQuery, and unfortunately it doesn't have properties like innerHTML . The code is below:
// Получение текстовых нод
function getTextNode(element) {
return $(element).addBack().contents().filter(function() {
return this.nodeType == 3;
});
}
// Переопределение. $target уже присвоен результат getTextNode
$target.first()[0].textContent = 'Линия текста <br /> Линия текста';
Answer the question
In order to leave comments, you need to log in
No, that's why it's a text node.
In general, you can do something like this:
$.fn.getTextNode = function() {
return this.contents().filter(function() {
return this.nodeType == 3;
});
}
$.fn.setTextNode = function(t){
this.before(t).remove();
}
//Получим текстовые ноды и установим одной из них значение
$(elem).getTextNode().first().setTextNode("<div></div>");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question