Skip to content Skip to sidebar Skip to footer

Pass E Parameter, Jquery

I have the following code in my document ready: $('a').click(function(e) { e.preventDefault(); var $this = $(this); var horizontalPadding = 30;

Solution 1:

function aFunction(e) {
    e.preventDefault();
    var $this = $(this);
    var horizontalPadding = 30;
    var verticalPadding = 30;
    $('<iframe id="externalSite" class="externalSite" src="' + this.href + '" />').dialog({
        title: ($this.attr('title')) ? $this.attr('title') : 'External Site',
        autoOpen: true,
        width: 800,
        height: 500,
        modal: true,
        resizable: true,
        autoResize: true,
        overlay: {
            opacity: 0.5,
            background: "black"
        }
    }).width(800 - horizontalPadding).height(500 - verticalPadding);            
}

$('a').click(aFunction);

jQuery will pass 'e' to the function you provide - but you must pass it without brackets, so you are passing a function object, and not the result of a function call.

Solution 2:

Do this:

functionaFunction(e) { ... }
$('a').click(aFunction);

The event argument is automatically passed.

Solution 3:

$('a').click();

or

$('a').trigger('click');

Post a Comment for "Pass E Parameter, Jquery"