Opened 11 years ago
Closed 11 years ago
#12347 closed enhancement (wontfix)
Proposed method: $.fn.htmlOf
Reported by: | cowboy | Owned by: | cowboy |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.8.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Sure, we have this:
$("#target").html("<p>new content</p>").addClass("to-target");
But why don't we have this?
$("<p>new content</p>").htmlOf("#target").addClass("to-paragraph");
I propose a new htmlOf
method that is something along these lines:
$.fn.htmlOf = function(target) { $(target).html(this); return this; };
See a Working example.
Thoughts?
Change History (7)
comment:1 Changed 11 years ago by
Owner: | set to cowboy |
---|---|
Status: | new → pending |
comment:2 Changed 11 years ago by
Status: | pending → new |
---|
The other primary "adding arbitrary element nodes to a target" methods exist in pairs:
$("#target").append("<p>new content</p>"); $("<p>new content</p>").appendTo("#target"); $("#target").prepend("<p>new content</p>"); $("<p>new content</p>").prependTo("#target"); $("#target").insert("<p>new content</p>"); $("<p>new content</p>").insertBefore("#target"); $("#target").after("<p>new content</p>"); $("<p>new content</p>").insertAfter("#target"); $("#target").replaceWith("<p>new content</p>"); $("<p>new content</p>").replaceAll("#target");
But then there's the html
method, which has been very, very lonely. Until now!
$("#target").html("<p>new content</p>"); $("<p>new content</p>").htmlOf("#target");
I don't bring this up just because I wanted it for some example I was writing. I also want to make the html
method feel happier.
Besides, think of how totally gross it looks if you want to do this right now in one line and still chain:
$("<p>new content</p>").appendTo($("#target").empty()).addClass("to-paragraph");
PS. If it's a file size thing, I'm totally cool with the method being called h
to save precious bytes:
$("#target").html("<p>new content</p>"); $("<p>new content</p>").h("#target");
comment:3 Changed 11 years ago by
The big difference of course being that .html()
only accepts strings, it is not the same type of method as the others that you've listed, which accept a range of input types.
Ignore the fact that it actually accepts more, that's not public API and is subject to change at any time.
comment:4 Changed 11 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I don't think we want to add more manipulation primitives in 1.9, especially ones that haven't been well proven. Perhaps there could be a plugin with a bunch of these? Or maybe it can be tackled in a future custom build system. But let's not leave this ticket open.
comment:5 Changed 11 years ago by
Resolution: | wontfix → fixed |
---|
Fix #12347 and #12384. Use a fresh div in jQuery.clean each time.
Regression was introduced in 22ad8723ce07569a9b039c7901f29e86ad14523c most likely because the clown who fixed http://bugs.jquery.com/ticket/4011 didn't add a unit test.
Changeset: b6a7d022eeb8c2cb0b065a311e53f9ea98554600
comment:6 Changed 11 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I'm not sure I see the benefit in additional API surface that reproduces functionality that is already available. Can you provide some use cases that illustrate any large scale benefits or improvements - thanks!