Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In my jQuery am displaying my results in a table formatted output, a part of my jQuery is

<td class='close' onclick='deleteItem(#ITEMID,#ITEMNAME)'></td>

here "close" is a CSS class and in this class I have cross mark image, if I click this cross mark the function(deleteItem) will be fired.

here what I want to do is if I click this cross mark a "delete confirmation box" should pop up and if I click yes this onclick event should fire, else if I click No nothing should happen.

How can I achieve this, can anyone help me....

This works, however it should be noted that this is not jQuery-specific and is just vanilla JavaScript. – crmpicco May 28, 2013 at 11:20
$(document).ready(function(){
  $(".del").click(function(){
    if (!confirm("Do you want to delete")){
      return false;
$('.close').click(function(){
var checkstr =  confirm('are you sure you want to delete this?');
if(checkstr == true){
  // do your code
}else{
return false;
function deleteItem(){
    var checkstr =  confirm('are you sure you want to delete this?');
    if(checkstr == true){
      // do your code
    }else{
    return false;

This may work for you..

Thanks.

$("a.removeRecord").live("click",function(event){ event.stopPropagation(); if(confirm("Do you want to delete?")) { this.click; alert("Ok"); alert("Cancel"); event.preventDefault(); return confirm('Are You Sure ?')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td class='close'></td>

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.