I used the following code to set the left margin for a div with id=""
document.getElementById('s4-ca').style.marginLeft = '0px';
However getting an error like Object Required!
UPDATE – My code
<script type="text/javascript">
var groupName;
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function(xData, Status) {
$(xData.responseXML).find("[nodeName=Group]").each(function()
{
groupName = $(this).attr("Name");
});
}
});
if($.trim(groupName) != 'ABC')
{
document.getElementById('s4-leftpanel').style.display = 'none';
document.getElementById('s4-ca').style.marginLeft = '0px';
}
</Script>
There’s nothing wrong with your JavaScript, just give the
<div>a matchingidproperty, then it should work fine, i.e.So there reason you’re getting the error is because
document.getElementById('s4-ca')doesn’t find a en element with a matchingid, so it’snull, and you can’t reference thestyleproperty on a null object.Also, when you set the
marginLeftthere’s no need to specify units for zero, you can use just0.