changing margin value using jQuery
I have below code if there is error msg. then the margin top of login form should be "0" and for the first error msg margin top should be "70px".
<span class="portlet-msg-error"> You have entered invalid data. Please try again. </span>
<span class="portlet-msg-error"> Authentication failed. Please try again.</span>
<div class="login-form" style开发者_高级运维="margin-top: 70px;"> Form Display here </div>
$('.login-form').css({'margin-top':'0px'}); // Login form
$('.portlet-msg-error:first').css({'margin-top':'70px'}); // Error Message
It may be marginTop
, I forget if jQuery can accept the full name or if you have to camelCase it when there are hyphens
EDIT Just checked, margin-top
seems to work
Try this:
if(error)
{
$(".login-form").css("margin-top", "0");
$(".portlet-msg-error:first").css("margin-top", "70px");
}
You can do this in CSS:
.login-form {
margin-top: 0px;
}
.portlet-msg-error:first-child {
margin-top: 70px;
}
The same in jQuery would be:
$('.login-form').css('margin-top', '0px');
$('.portlet-msg-error:first-child').css('margin-top', '70px');
So you see there is no real reason to use jQuery in this case.
精彩评论