Given the below code I expect both foo and bar to have a div inside of them with the appropriate data attribute, but only the one using attr works. Am I missing something? Is this possible? Can someone explain /why/ this works the way it does? I tried to look at the api docs for each method, but didn't see anything to suggest that it shouldn't work.
<div id="foo">asdd</div>
<div id="bar">asdasd</div>
$("#foo").append($('<div>').attr("data-something", "a value"));
$("#bar").append($('<div>').data("something", "a second value"));