How to append/prepend/create a text node with jQuery

前端 未结 3 1548
天命终不由人
天命终不由人 2020-12-11 00:03

Possible Duplicate:
Escaping text with jQuery append?

My HTML is somewhat like this:

3条回答
  •  孤街浪徒
    2020-12-11 00:22

    The createTextNode approach is probably the best way to go. If you want to have a jQuery-ish syntax, you could make a plugin.

    $.fn.appendText = function(text) {
        return this.each(function() {
            var textNode = document.createTextNode(text);
            $(this).append(textNode);
        });
    };
    

提交回复
热议问题