0

Title doesn't actually reflect what I'm trying to explain. Is it possible to achieve below with jQuery

<a href="#" onclick="alert('test');">test</a>

when users clicks on test link jQuery takes control over default alert function and displays a jQuery modal window or something similar doesn't really matter.

nLL
  • 5,662
  • 11
  • 52
  • 87

3 Answers3

3
alert = function(foo) {
    // some functionality
};

Browser support may vary. It appears to work OK in Fx 4.0b7.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Something like this might works ( based on the initial suggestion from @Quentin ):

// alert replacement ##
var alerter;
alert = function(foo) {

    //console.log(foo);
    if ( !jQuery('#alerter').length ) {
        jQuery("body").append( jQuery('<div>', { id: 'alerter'}) ); // make it ##
    }
    jQuery('#alerter').addClass('alerter').text(foo).slideDown("fast");
    clearTimeout(alerter);
    alerter = setTimeout(function(){
        jQuery('#alerter').slideUp("fast");
    }, 5000);
}
Q Studio
  • 1,811
  • 3
  • 16
  • 18
-1

Here is an example where the default alert is never called. Instead the popup is displayed. Not certain if calling the default alert is requirement.

http://jsfiddle.net/pBsw6/

Hope this helps.

Bob

rcravens
  • 8,320
  • 2
  • 33
  • 26
  • this doesn't answer the question – ifaour Dec 19 '10 at 13:32
  • because you are clearly asking for a way to override the "default" function! I'm gonna release the downvote but please rephrase your question and ask your questions in a better way next time. **EDIT** i can't undo the vote now! – ifaour Dec 19 '10 at 15:01