如何获取动态javascript HTML元素与Jquery进行交互

时间:2020-08-15 16:13:34

标签: javascript jquery

在我的程序中,我试图创建一个下拉列表。我面临的问题是,jQuery无法识别我使用动态JavaScript创建的其他HTML元素。

这是我所从事的事的一个例子:

var notification_box = make_element("div", "Notifications: ", "notify");
notification_box.id = "notification_box";

console.log($("#notification_box"));

function make_element(tag, text, element_class)
{
     var element = document.createElement(tag);
     if(text != undefined)
     {
         var textnode = document.createTextNode(text);
         nodeValue = text;
         element.appendChild(textnode);
     }

     if(element_class !== undefined)
     {
          element.classList.add(element_class);
     }
            
     return element;
}
    
    

console.log返回的内容是:

w.fn.init(0)

0 个答案:

没有答案