//define the function function alertsomething(){ alert("Hey, This is an alert inside that function"); } //function works when button clicks $("#btd").click(function(){ alertsomething(); }) //function automatically when page loads $(document).ready(function(){ alertsomething(); }) $(function() { $("button").click(function() { $(this).toggleClass("active"); }); $(".item").each(function(i, e) { var button = $(this).find("button"); ranNum = Math.floor(Math.random() * (6 - 2 + 1)) + 2; if ((i + 1) % ranNum == 0) { $(e).button.click(); } }); }); $(function() { $("button").click(function() { $(this).toggleClass("active"); }); $(".item").each(function(i, e) { var button = $(this).find("button"); ranNum = Math.floor(Math.random() * (6 - 2 + 1)) + 2; if ((i + 1) % ranNum == 0) { $(e).button.click(); } }); $(function() { var toggleActive = function() { $(this).toggleClass("active"); }; $("button").click(toggleActive); $(".item").each(function(i, e) { var button = $(this).find("button"); ranNum = Math.floor(Math.random() * (6 - 2 + 1)) + 2; if ((i + 1) % ranNum == 0) { toggleActive.call(button); } }); }); });
$(function() { $("button").click(function() { $(this).toggleClass("active"); }); $(".item").each(function(i, e) { var button = $(this).find("button"); ranNum = Math.floor(Math.random() * (6 - 2 + 1)) + 2; if ((i + 1) % ranNum == 0) { $(e).button.click(); } }); });

تعليقات

المشاركات الشائعة من هذه المدونة