Vinayak Shivapuje Vinayak Shivapuje - 3 months ago 13
CSS Question

jQuery not working for button event

var myVar;
function colorChanger() {
myVar = setInterval(function() {
var r,g,b,shadow,bottom,top;
r = Math.floor((Math.random() * 253 ) + 1);
g = Math.floor((Math.random() * 253 ) + 1);
b = Math.floor((Math.random() * 253 ) + 1);
shadow = Math.floor((Math.random() * 20 ) + 5);
bottom = Math.floor((Math.random() * 80 ) + 1);
bbottom = Math.floor((Math.random() * 80 ) + 7);
ttop = Math.floor((Math.random() * 180 ) + 6);
top = Math.floor((Math.random() * 200 ) + 9);
size = (Math.random() * 100 ) + 10;
/* $("*").css("box-shadow",""+top+"px 0 "+shadow+"px rgb("+r+","+g+","+b+"), "+(-top)+"px 0 "+shadow+"px rgb("+r+","+g+","+b+"),0 "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"),0 "+(bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+")"); */
$("#startinterval").css("bottom","50%");
$("#startinterval").css("top",ttop+"px");
document.getElementById("123").style.color = "rgba("+r+","+g+","+b+",0.3)";
document.getElementById("123").style.textShadow = top+"px "+(bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"), "+(-top)+"px "+bottom+"px "+shadow+"px rgb("+r+","+g+","+b+"),"+top+"px "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"),"+(-top)+"px "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+")";
document.getElementById("123").style.textShadow = top+"px 0 "+shadow+"px rgb("+r+","+g+","+b+"), "+(-top)+"px 0 "+shadow+"px rgb("+r+","+g+","+g+"),0 "+(-bottom)+"px "+shadow+"px rgb("+b+","+g+","+b+"),0 "+(bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+")",top+"px "+(bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"), "+(-top)+"px "+bottom+"px "+shadow+"px rgb("+g+","+r+","+b+"),"+top+"px "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+"),"+(-top)+"px "+(-bottom)+"px "+shadow+"px rgb("+r+","+g+","+b+")";
document.getElementById("13").style.backgroundColor = "rgba("+b+","+r+","+g+",0.2)";
document.getElementById("13").style.bottom = bottom+"%";
document.getElementById("13").style.top = top+"%";
document.getElementById("choosen").innerHTML = "rgb("+r+","+g+","+b+")";
$("button").click(function() {
$("button").css({"border-radius":bottom+"px"});
});
}, 20);
}


HTML code :

<div align="center">
<h2 style="font-weight: 900;font-size: 40px, -webkit-animation-delay: 5s;"><p id="123">Random Text</p></h2>
<button class="btn btn-info" onclick="colorChanger()" id="startinterval">start Animation</button>
<button onclick="stopColor()">stop Animation</button>
</div>


I recently started with jQuery and I'm really sorry if this is a lame question. In above code On Clicking the button it's supposed to change the radius of the button to "variable" value but it's not working.I tried using className, element-id but no luck. Any help will be appreciated. Thankyou.

Answer

For trigger click event on button you have to add below line

    $("button").trigger( "click" );
    $("button").click(function() {
                    $("button").css({"border-radius":bottom+"px"});
                });

This will trigger the click event on button.