#8176 closed enhancement (wontfix)
appendTo should accept 'context' parameter
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | manipulation | Version: | 1.5 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
appendTo() should accept 'context' parameter so that it is possible to do something like this:
select = $("<select>").addClass("choices"); $("<option>").text("Hello").appendTo(".choices", select);
Change History (4)
comment:1 Changed 12 years ago by
Component: | unfiled → manipulation |
---|---|
Owner: | set to niloy_mondal@… |
Priority: | undecided → low |
Status: | new → pending |
Type: | feature → enhancement |
comment:2 Changed 12 years ago by
Status: | pending → new |
---|
Thank you for the review.
appendTo currently assumes the window DOM as the 'context' and provides no way to specify otherwise. $() accepts the second parameter as the context.
The most common use case would be when using $.tmpl().
var page = $("#template").tmpl(object); //Say the template contains a select box with id="country", but its options //are going be populated using ajax $.getJSON('get-countries.php', function(countries){ for (var i = 0; i < countries.length; i++){ $("<option>").text(countries[i]).appendTo("#country", page); //Right now I have to do it like this... //var opt = $("<option>").text(countries[i]); //$("#country", page).append(opt); } });
comment:3 Changed 12 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Take a look at the docs: http://api.jquery.com/appendTo/
Scroll to this: $('h2').appendTo($('.container'));
And then, take a look at this: http://jsfiddle.net/rwaldron/GxBAt/2/
I think you'll find this meets your needs! Thanks again!
comment:4 Changed 12 years ago by
Replying to niloy_mondal@…: Did you even try the code snippet I provided above? It basically does the same as the code provided rwaldron
Another test case variation.
Thanks for taking the time to contribute to the jQuery project by writing an enhancement request.
Unfortunately your request is rather scarce, you don't go into detail how this modification should work / is supposed to behave. You also don't provide any use cases (2-3 at least would be good) where this would prove to be useful to the vast majority of the jQuery user base.
The missing explanation on why this is needed and is something that can't be done (or only with difficulty) with the current available method signatures in jQuery makes it difficult to judge the validity of this request.
Also I don't really understand the intention of the code snippet you added to your description. Isn't the following snippet already achieving what you are aiming for by just using the currently available method signature?