SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLDocument]' is not a valid selector

不问归期 提交于 2019-12-08 22:07:21

问题


I am trying to get all field values from a sharepoint list item on a display template, the ctx.CurrentItem only gets some values but not all I need.

I tried the following code, but I get the error on the title

SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLDocument]' is not a valid selector.

function GetListItemById_Success(sender, args) 
{ 
   var id = ListItem.get_id(); 
   var title = ListItem.get_item("Title"); 
   alert("Updated List Item: \n Id: " + id + " \n Title: " + title); 
}

// Display an appropriate error message 
function GetListItemById_Fail(sender, args) 
{ 
   alert("GetListItemById Failed. \n" + args.get_message() + "\n" + args.get_stackTrace());
}

$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(CustomAction, "sp.js"); });

function CustomAction(){
var clientContext =  new SP.ClientContext.get_current();
var web = clientContext .get_web(); 
var targetList = clientContext.get_web().get_lists().getByTitle('Test Document Library');
var list = web.get_lists().getByTitle('Test Document Library'); 
ListItem = list.getItemById(ctx.CurrentItem.DocId);
clientContext.load(ListItem, "Id", "Title"); 
clientContext.executeQueryAsync(GetListItemById_Success, GetListItemById_Fail); 
}

回答1:


I got the same exception after upgrading jQuery located in top level site. The reason was reference to old jQuery library in subsite master page.



来源:https://stackoverflow.com/questions/22577783/syntaxerror-failed-to-execute-queryselector-on-document-object-htmldocum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!