I have the following actions in my document.ready.
What I'm trying to do is to selectively remove a div with ID that ends with '_View_memberDirectory'. Therefore, I'm adding the following code which works if it's not part of my function below. However, when I have it inside my function it does not work. At the moment the boolean is always true. Any ideas?
$("[id$='_View_memberDirectory']").bind('DOMNodeInserted', function (event) {
$(this).empty();
});
My script:
<script type="text/javascript">
$(document).ready(function () {
$(function () {
var bIsContact;
bIsContact = IsContact();
if (bIsContact.responseText === "true") {
//does not work here
$("[id$='_View_memberDirectory']").bind('DOMNodeInserted', function (event) {
$(this).empty();
});
}
else {
e.preventDefault;
}
});
//works here <-------
});
Edit: Added IsContact() function
function IsContact() {
var friendId = <%= Request.QueryString("UserID").ToString()%> + '';
var sf = $.ServicesFramework(<%=ModuleId %>);
var serviceUrl = sf.getServiceRoot('OmniBody');
var obj = { "friendId": friendId };
return $.ajax({
type: "POST",
cache: false,
url: serviceUrl + "/ModuleTask/IsContact",
beforeSend: sf.setModuleHeaders,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(obj)
}).done(function (result) {
}).fail(function (xhr, result, status) {
alert(result);
});
}