You are calling the .css()
method jQuery "wrong": you have no choice for execute a function as soon as it finishes. In part, because you do not really need it: it runs synchronously, so even if you were to admit a function to be executed after the CSS change, there would be no difference between putting the code in that function or directly after .css()
.
The solution is simple: remove the function and put the code just behind the .css
. So, instead of doing:
$(".relat").css({"display":"block"}, function(){
alert("fsdss22222");
})
That does not work, what you should do is:
$(".relat").css({"display":"block"});
alert("fsdss22222");
that will work. Here you can see it working:
function miFuncion() {
alert("123456");
}
$(document).ready(function () {
$('.boton').click(function(){
if ( $('.relat')=="block") {
}else{
$(".relat").css({"display":"block"})
miFuncion();
}
});
});
.boton{
width: 100px;
height: 100px;
background: slateblue;
color: white;
cursor: pointer;
}
.relat{
width: 300px;
height: 300px;
background: tan;
color: red;
display: none;
}
.animado{
width: 100px;
height: 100px;
background: brown;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="boton">Click aqui</div>
<div class="relat">relat
<div class="animado">animado</div>
</div>
And if you want it to be an anonymous function instead of one defined in your code, simply create a function and call it automatically. The idea is the same:
$(document).ready(function () {
$('.boton').click(function(){
if ( $('.relat')=="block") {
}else{
$(".relat").css({"display":"block"});
// aquí puedes definir tu función anónima y llamarla
(function() {
alert("123456");
})();
}
});
});
.boton{
width: 100px;
height: 100px;
background: slateblue;
color: white;
cursor: pointer;
}
.relat{
width: 300px;
height: 300px;
background: tan;
color: red;
display: none;
}
.animado{
width: 100px;
height: 100px;
background: brown;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="boton">Click aqui</div>
<div class="relat">relat
<div class="animado">animado</div>
</div>