How to stop an anchor from redirecting using JQuery

Change your click event handler to this

$('a').click(function(e){
    var id = $(this).attr('id');
    if (id == 'yes')
    {
        e.preventDefault();
        e.stopPropagation();
    }
    else
    {
        //redirect
    }
});

Please use http://api.jquery.com/event.preventDefault/

demo http://jsfiddle.net/aRBY4/6/

e.preventDefault() 

quote

If this method is called, the default action of the event will not be triggered.

Also if I may suggest read this: .prop() vs .attr()

Hope this helps,

sample code

  $('a').click(function(event){
    event.preventDefault();
    //do whatever
  });

In your case please try this

$(document).ready(function() {
    $('a').click(function(event) {
        var id = $(this).attr('id');
        if (id == 'yes') {
            event.preventDefault();
            //i want to prevent
        } else {
            //redirect
        }
    });
});​