On the editform of an item, i have added a cEWP and hidden the default editform webpart. The CEWP calls a html file which references jquery and spservices. The html shows a few fields of the SP List item one among which is a multiline text field called comments where I display all the versions of a comment using spservices, getversioncollection method, SPservices to retrieve version history of items in SharePoint List 2007?
But this showed $ is undefined for the SPServices. For this I added a
var JQ=jQuery.noconflict(true);
and I was able to use JQ in the the SPServices method. This code was called from the document.ready, e.x.
$(document).ready(function(){
GetComments();
});
There are buttons on the form which have jquery functionality. All of this was working fine. Now when i moved the code to another environment, I get the error '$ is not a function' inside the button click events. When I comment the GetComments code, the button functionality works. I am not sure how to resolve this as the same code is working in one system but not another.
I was able to reproduce similar situation in script below. Can someone tell me how to fix this?
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> </script>
<script>
$(document).ready(function(){LoadData();});
function LoadData()
{
$("p").text("jQuery is still working!");
DisplayComments();
}
function DisplayComments()
{
var j=$.noConflict(true);
//call spservices getversioncollection method here
j("p").append("<br>conflict jQuery is still working!");
}
function foo()
{
$("p").append("<br>jQuery is not recognized here");
}
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button onclick='foo()'>Test jQuery</button>
</body>
</html>