Jquery - Css "transform:scale" Affects '.offset()' Of Jquery
I'm Trying To do Validation in jQuery. It'll produce error after blur event occurs by checking whether the given input is empty. Based on that, it'll create a
Solution 2:
here is the working solution
CSS
.inpt:focus {
background:#fff;
color:#222;
border:2px solid #000;
}
.err {
background:pink;
border:2px solid #f00;
color:#a00;
}
.errdiv {
position:absolute;
height:30px;
display:inline-block;
padding:5px;
border-radius:5px;
background:#a00;
border:1px solid #a44;
color:#fff;
text-align:center;
font-weight:bolder;
visibility:visible;
opacity:0;
}
HTML
<center>Hello Every One!</center>
<hr>
<center>
<input class="inpt" placeholder="name" type="text" /><br />
<input class="inpt" placeholder="email" type="text" /><br />
<input class="inpt" placeholder="password" type="password" /><br />
</center>
<center>
Just Try Focusing and Bluring the Inputs
</center>
JAVASCRIPT
$(document).ready(function() {
$(".inpt").blur(function() {
// Check Input for validation.
$(".errdiv").remove(); //Remove Any Previous Error.
var vl = $(this).val();
var vl1 = vl.split(" ").join("");
if (vl == "" || vl1 == "") {
// Input is Empty Mark It red.
$(this).addClass("err");
}
});
$(".inpt").focus(function() {
//Check Whether Input is marked Red or Not (hasClass) err?
// $(".errdiv").remove(); //Remove Any Previous Error.
if ($(this).hasClass("err")) {
// Input is Marked!
$(this).removeClass("err");
// var tp=$(this).offset().top+12;// not needed
// var lf=$(this).offset().left+$(this).width()+12;// not needed
// // Add Error Div and appropriate Message.
$('<div class="errdiv">*This is Required.</div>').insertAfter(this);
$(".errdiv").animate({
"visibility": "visible",
"opacity": "1"
}, 1000); //Show What is The Error?
}
});
});
A bit of modification that is all
Remove top and left property from your .errdiv class and append the div dynamically after the element
Post a Comment for "Jquery - Css "transform:scale" Affects '.offset()' Of Jquery"