Javascript 使用document.querySelector获取tr元素

Javascript 使用document.querySelector获取tr元素,javascript,jquery,html,frontend,Javascript,Jquery,Html,Frontend,我试图使用document.querySelector语句获取tr元素,但得到: TypeError: tempNode.querySelector(...) is null 我的Javascript选择器是:document.querySelector(“行模型”) 这与其他元素(确切地说是div)一起工作,但我使用它尝试了其他选择器(使用数据类型、tr等,但总是得到相同的错误)…然后在浏览器控制台中检查元素的存在,元素的HTML如下所示: <table> <

我试图使用
document.querySelector
语句获取tr元素,但得到:

TypeError: tempNode.querySelector(...) is null
我的Javascript选择器是:
document.querySelector(“行模型”)
这与其他元素(确切地说是div)一起工作,但我使用它尝试了其他选择器(使用数据类型、tr等,但总是得到相同的错误)…然后在浏览器控制台中检查元素的存在,元素的HTML如下所示:

<table>
        <tbody>
    <tr class="" id="row-model" data-id="myid" data-type="rowtemplate">
        <td class="category">
            <a href="" title="Go to category" id="category"></a>
        </td>
        <td class="title  showTipTip">
            <a data-cats="" href="#profile" id="title" aria-controls="profile" role="tab" data-toggle="tab" title="" data-id="" class="spotlink" address="true"></a>
        </td>
        <td class="comments">
            <a class="spotlink" href="#comments" title="" id="commentValue"> commentValue
            </a>
        </td>

        <td class="genre">
            <a href="" title="Search spot in category" id="genre"> catdesc</a>
        </td>
        <td class="poster">
            <a href="" title="Search spot from " id="poster">poster</a>
        </td>
        <td class="date" id="since"></td>

        <td class="filesize" id="filesize">

        </td>
        <td class="nzb">
            <a href="" title="Download NZB (n)" class="nzb" target="_blank" id="nzbdownload">NZB</a>
        </td>
        <td class="multinzb">
            <input onclick="multinzb()" name="messageid[]" value="" type="checkbox">
        </td>
    </tr>
        </tbody>
    </table>

另外,我将该表放在一个带有隐藏类(引导)的div中,也许它会影响它?

在将该行呈现到页面之前,是否引用该行?如何调用代码?@epascarello不,它在一个函数中,当用户按下按钮并且内容已经加载时,我会调用该函数。什么是tempNode?我们需要更多的上下文。您可以使用js代码吗?您是否在将行呈现到页面之前引用该行?你如何调用代码?@epascarello不,它在一个函数中,当用户按下一个按钮,内容已经加载时,我会调用这个函数。什么是tempNode?我们需要更多的上下文。你能看看js代码吗?
 $('#catalog').each(function(){
        var tempNode = document.querySelector("#row-model").cloneNode(true); //I clone the element and then append it to another table
       tempNode.querySelector("a #category").textContent = "test";
      $('#spotsTable tr:last').after(tempNode);
    });