javascript - ("#" + items).append is not a function - Stack Overflow

`shipment` is uniquenumber var `shipment` = this.Shipment;$('<div id=' + this.Shipment

 // `shipment` is unique  number 

        var `shipment` = this.Shipment;
             $('<div id=' + this.Shipment + '>' + this.Shipment +'</div>').click(function () {


                 _Services.invoke({
                     method: 'GetOrdersGrid',
                     data: { ShipmentNumber: shipment },
                     success: function (shipment) {
                         paintOrders(`shipment`);

the function gets a number of div and needs to put the TEXT into the div

<div id="11626">TEXT</div>
<br>
<div id="12109">TEXT</div>

ERROR: ("#" + items).append is not a function [Break On This Error] ('#' + items).append($(container));

WHEN i use the sollar sign $('#' + items).append($(container));

ERROR uncaught exception: Syntax error, unrecognized expression: #[object Object]

WHEN i use without the #
 $(items).append(container); or  $(items).append($(container));

(this[0].ownerDocument || this[0]).createDocumentFragment is not a function
[Break On This Error] var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(), 
 // `shipment` is unique  number 

        var `shipment` = this.Shipment;
             $('<div id=' + this.Shipment + '>' + this.Shipment +'</div>').click(function () {


                 _Services.invoke({
                     method: 'GetOrdersGrid',
                     data: { ShipmentNumber: shipment },
                     success: function (shipment) {
                         paintOrders(`shipment`);

the function gets a number of div and needs to put the TEXT into the div

<div id="11626">TEXT</div>
<br>
<div id="12109">TEXT</div>

ERROR: ("#" + items).append is not a function [Break On This Error] ('#' + items).append($(container));

WHEN i use the sollar sign $('#' + items).append($(container));

ERROR uncaught exception: Syntax error, unrecognized expression: #[object Object]

WHEN i use without the #
 $(items).append(container); or  $(items).append($(container));

(this[0].ownerDocument || this[0]).createDocumentFragment is not a function
[Break On This Error] var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(), 
Share Improve this question edited Nov 25, 2011 at 18:46 Kristina88 asked Nov 25, 2011 at 18:00 Kristina88Kristina88 571 silver badge7 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 5

You're missing a $

Change

('#' + items).append($(container));

to

$('#' + items).append($(container));

Presuming, of course, that you have an element with id set to whatever items resolves to.

you're missing the $

$('#' + items).append($(container));

Try this $('#' + items).append($(container)); instead of (items).append($(container));

// items is unique number

function paintOrders(items) {
    var container = '<div>';
    $.each(items, function () {
        container += 'TEXT' + '<br/>';
    });
    container += '</div>';

    $(items).append($(container));
}

Try this code:

function paintOrders(items) {
  var lastIndex = items.length - 1;
  $.each(items, function (index, item) {
    if (index == lastIndex)
      $('#'+item).append('<div>'+'TEXT'+'</div>');
    else
      $('#'+item).append('<div>'+'TEXT'+'</div>'+'<br/>');
  });
}

Maybe this code is not exectly what you need but you might find some leads from it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744849323a4597032.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信