To check which id has been clicked
$('#btn1, #btn2').click(function () { if (this.id == 'btn1') { alert('btn1 clicked'); } else if (this.id == 'btn2') { alert('btn2 clicked'); } });
Alert when click #target
$( "#target" ).click(function() { alert( "Handler for .click() called." ); });
Click on #WhenClickThis will hide the #HideThis and show the #ShowThis
$("#WhenClickThis").click(function () { $("#HideThis").hide(); $("#ShowThis").fadeIn('500'); });
Click .button will have smooth scrolling to .scrolltothis element
$(".button").click(function() { $('html,body').animate({ scrollTop: $(".scrolltothis").offset().top},'slow'); });
Show and hide upon click with css properties
$("#NextButton").click(function() { $("#Page1").css("display", "block"); $("#Page0").css("display", "none"); });
Use the javascript variables as a parameter in a jquery selector
$("input").click(function(){ var name = $(this).attr("name"); $('input[name="' + name + '"]').hide(); });