Seen
Seen

Reputation: 4194

Partial view render order with Jquery

I have two questions on the render order of the partial view

  1. If I have the $.ready(), $.live in the partial view, when are the initiated, in the initiation of this partial view or the whole document?
  2. I cannot reference a new css file on the partial view. Do I have to reference those style files in the layout?

Upvotes: 0

Views: 218

Answers (1)

BumbleB2na
BumbleB2na

Reputation: 10763

You can have multiple $(document).ready() calls in the same document. Each $.ready() or $.live() are rendered in the same order that they appear in the code.

In your partial view you can dynamically insert your css script to the head of the page:

<script type="text/javascript">
    $(document).ready(function() {
        $('<link href="' + @Url.Content("~/Content/Site.css") + '" rel="stylesheet" type="text/css" />').appendTo('head');
    });
</script>

Users may notice a slight delay for these styles to take effect after the DOM has loaded.

Upvotes: 1

Related Questions