#208 closed enhancement (worksforme)
$.load should automatically be JQuerified
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | ajax | Version: | |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
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 (4)
comment:1 Changed 16 years ago by
comment:2 Changed 16 years ago by
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 16 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
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 16 years ago by
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.
Could you explain this some more?