Change margin value using jQuery

I have the code below if there is an msg error. then the upper limit of the login field should be "0", and for the first error, the upper limit of the msg message 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> 
+4
source share
3 answers
 $('.login-form').css({'margin-top':'0px'}); // Login form $('.portlet-msg-error:first').css({'margin-top':'70px'}); // Error Message 

It could be marginTop , I forgot if jQuery can take the full name, or if you need its camelCase when there are hyphens

EDIT Just tested, margin-top works

+8
source

Try the following:

 if(error) { $(".login-form").css("margin-top", "0"); $(".portlet-msg-error:first").css("margin-top", "70px"); } 
+2
source

You can do this in CSS:

 .login-form { margin-top: 0px; } .portlet-msg-error:first-child { margin-top: 70px; } 

The same thing in jQuery would be:

 $('.login-form').css('margin-top', '0px'); $('.portlet-msg-error:first-child').css('margin-top', '70px'); 

So you see that in this case there is no real reason to use jQuery.

+1
source

Source: https://habr.com/ru/post/1334463/


All Articles