user3004110
user3004110

Reputation: 969

How to merge two functions in JQuery

I am successfully opening a JQuery dialog modal. My first JQuery function opens dialog and my second jquery function set the dialog position to top. I want to merge these two functions, please see my following code:-

$(function () {
    $("#modal-registration").dialog({
        autoOpen: false,
        height: 400,
        width: 380,
        model: true
    });
    $('#modal-registration').dialog({ position: 'top' });
});

In above code how can i merge these two functions like $("#modal-registration").dialog({autoOpen:false, et:cetera}) and the $('#modal-registration').dialog({ position: 'top' }); with each other?, thanks.

Upvotes: 0

Views: 68

Answers (4)

M J
M J

Reputation: 81

As per your fiddle link, you can do following :

$( "#dialog" ).dialog({    
    autoOpen: false,
    height: 400,
    width: 380,
    model: true,
    position : [0,0]        //mention the attribute here itself
});
$( "#opener" ).click(function() {
    $( "#dialog" ).dialog( "open" );
});

Its working fine.

Upvotes: 0

codefreaK
codefreaK

Reputation: 3662

DEMO

HTML

<button id="opener">open the dialog</button>
<div id="dialog" title="Dialog Title">I'm a dialog</div>

Jquery

$('#dialog').dialog( 'option', 'position', [0, 0] );

change [0,0] to x,y coordinates of your need

Upvotes: 0

Vasiliy vvscode Vanchuk
Vasiliy vvscode Vanchuk

Reputation: 7159

$("#modal-registration").dialog({
                autoOpen: false,
                height: 400,
                width: 380,
                model: true,
                position: 'top' 

            })

Why not in single command?

Upvotes: 0

dev
dev

Reputation: 3999

Can you not just stick the position property in with the first dialog call? Like

$("#modal-registration").dialog({
  autoOpen: false,
  height: 400,
  width: 380,
  model: true,
  position: 'top'
});

Upvotes: 1

Related Questions