0

I'm familiar with codes with forms like this:

$(document).ready(function() {}) 

Or

(function(){})()

But I'm confused when I saw codes are like this

$(function () {
    $(".modal-link").click(function (event) {
        event.preventDefault()
        $('#myModal').removeData("modal")
        $('#myModal').modal({remote: $(this).attr("href")}).css({
            'width': function () {
                return ($(document).width() * .9) + 'px';
            },
            'margin-left': function () {
                return -($(this).width() / 2);
            }
        });
    })
})

It seems that $ is a jquery function, why should the function be wrapped in this function? Is is the same as $(document).ready(function() {})?

Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237

1 Answers1

1

Yes, $(handlerFunction) and $(function() {}) have the same effect as $(document).ready(handlerFunction) and $(document).ready(function() {}). It's just a shortcut to save on typing.

As explained by the doco.

nnnnnn
  • 147,572
  • 30
  • 200
  • 241