Bug Tracker

Modify

Ticket #208 (closed enhancement: worksforme)

Opened 7 years ago

Last modified 6 years ago

$.load should automatically be JQuerified

Reported by: anonymous Owned by:
Priority: minor Milestone:
Component: ajax Version:
Keywords: Cc:
Blocking: Blocked by:

Description

Would be nice if JQuery assumed you want to use it on HTML files loaded into elements using .load, instead of having to put everything into a function and then use that function in a callback. It can make code messy quick.

Change History

comment:1 Changed 7 years ago by joern

Could you explain this some more?

comment:2 Changed 7 years ago by anonymous

Basically document.ready is the default callback for .load. If I put something like $(".hello").addClass("world"); in my document ready, and I load some content that uses the "hello" class it does not add the "world" class added to the content that was just loaded.

You can get around it by doing a myready function which contains all the stuff you want to do, and call that function from the load callback, and in document.ready, but it's rather non-intuitive.

comment:3 Changed 7 years ago by joern

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

Defining your DOM ready code inside a single function and passing that function to both $(document).ready and as a load() callback isn't what I'd call messy. On the other hand, automatically calling all events registered for document.ready when doing a load would result in quite unexpected behaviour.

comment:4 Changed 7 years ago by john

I have to agree with Joern. Disregarding the fact that it would be really difficult to implement, having code be applied on .load() would definitely be unexpected, and possibly unwelcome.

For example:

$("ul").addClass("data"); $("#foo").load("some-ul.html");

What if I don't want the 'data' class being applied to my incoming ul element? Should I be forced to go through and remove everything that was added?

An optional implementation might be an interesting project to consider, some day. For that reason, I've added it to the HardProblems page.

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.