jQuery htmlOf plugin
http://benalman.com/
by Ben Alman
HTML
<div id=a></div>
<div id=b></div>
<div id=c></div>
<div id=d></div>
CSS
body {
margin: 10px;
}
div {
background: #eee;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
p {
padding: 5px;
}
p + p {
margin-top: 10px;
}
.test {
background: #afa;
border: 1px solid #0a0;
}
JavaScript
// seriously, why isn't this in core?
(function($) {
// chaining = winning
$.fn.htmlOf = function(target) {
$(target).empty();
return this.appendTo(target);
};
}(jQuery));
$("<p>test a</p>").htmlOf("#a").addClass("test");
$("<p>test b</p><p>test b</p>").htmlOf("#b").addClass("test");
$("<p>test c + d</p><p>test c + d</p>").htmlOf("#c, #d").addClass("test");