Bug Tracker

Modify

Ticket #11560 (closed enhancement: plugin)

Opened 15 months ago

Last modified 15 months ago

.ready() should not ignore the selector

Reported by: john.firebaugh Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

Currently, $(<selector>).ready() ignores the selector and acts as though document was passed. I suggest that it instead act like other event binding functions, and call the callback with this bound to each matching element, or not at all if no elements match.

In particular, this would be convenient for including page-specific actions in a site's bundled assets. Assuming that a page was uniquely identified, for example with an id at the body element, page specific code could be isolated:

// index.js
$("#index").ready(function () {
  // page specific code for index page
});

// post.js
$("#post").ready(function () {
  // page specific code for post page
});

Now index.js and post.js can be concatenated and minified, and the resulting bundle downloaded only once, and still each page will run only the correct initialization code.

Change History

comment:1 Changed 15 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to plugin

Sorry, nope. We're not going to mess with those semantics, it would no doubt break code. You could easily write a plugin to do it though.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.