Skip to main content

Bug Tracker

Side navigation

#12347 closed enhancement (wontfix)

Opened August 19, 2012 05:16PM UTC

Closed August 28, 2012 09:13PM UTC

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?

Attachments (0)
Change History (7)

Changed August 19, 2012 05:29PM UTC by rwaldron comment:1

owner: → cowboy
status: newpending

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!

Changed August 19, 2012 06:02PM UTC by cowboy comment:2

status: pendingnew

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");

Changed August 19, 2012 06:07PM UTC by scottgonzalez comment:3

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.

Changed August 20, 2012 11:50PM UTC by dmethvin comment:4

resolution: → wontfix
status: newclosed

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.

Changed August 28, 2012 09:11PM UTC by Dave Methvin comment:5

resolution: wontfixfixed

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

Changed August 28, 2012 09:12PM UTC by dmethvin comment:6

resolution: fixed
status: closedreopened

Changed August 28, 2012 09:13PM UTC by dmethvin comment:7

resolution: → wontfix
status: reopenedclosed

NO NO NO!