views:

42

answers:

2

Dear all

I am newbie to jQuery and loves it

Can any one give me a small jQuery code snippet to Show an alert/Div when a button (with id btnSave ) being clicked .

+1  A: 

You should do something like this:

 <div id='alert'>ALERT!</div>

 $('#btnSave').click( function() {
  $('#alert').show();
 });
Pim Jager
Don't forget document ready though.
MrHus
I am getting "Object Required Error" after that I can see the alertThis is my code$(document).ready(function(){ $('#btnDeleteAdUser').click(function(){ alert(2) });})Can anyone debug ?
Shyju
A: 
$(function() {
  $("#btnSave").click(function() {
    alert("Alert");
  });
});

or

<div id="alert">
<p>Some alert.</p>
<input type="button" id="ok" value="OK">
</div>

with:

$(function() {
  $("#btnSave").click(function() {
    $("#alert").show();
  });
  $("#ok").click(function() {
    $("#alert").hide();
  });
});

Note: I wouldn't actually do it that way. Instead I'd use an existing plug-in like jQuery UI dialog.

cletus