Side navigation
#8176 closed enhancement (wontfix)
Opened February 04, 2011 02:18PM UTC
Closed February 04, 2011 04:36PM UTC
Last modified February 04, 2011 05:01PM UTC
appendTo should accept 'context' parameter
Reported by: | niloy_mondal@yahoo.com | Owned by: | niloy_mondal@yahoo.com |
---|---|---|---|
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);
Attachments (0)
Change History (4)
Changed February 04, 2011 02:54PM UTC by comment:1
_comment0: | 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? \ {{{ \ var select = $("<select>").addClass("choices"); \ $("<option>").text("Hello").appendTo(select); \ }}} \ → 1296831320861182 |
---|---|
component: | unfiled → manipulation |
owner: | → niloy_mondal@yahoo.com |
priority: | undecided → low |
status: | new → pending |
type: | feature → enhancement |
Changed February 04, 2011 04:02PM UTC by comment:2
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); } });
Changed February 04, 2011 04:36PM UTC by comment:3
_comment0: | 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/ → 1296837461384685 |
---|---|
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!
Changed February 04, 2011 05:01PM UTC by comment:4
_comment0: | Replying to [comment:2 niloy_mondal@…]: \ Did you even try the code snippet I provided above? It basically does the same as the code provided rwaldron \ \ Another [http://jsfiddle.net/jitter/tZ7wY/ test case] variation. → 1296838918321887 |
---|
Replying to [comment:2 niloy_mondal@…]:
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.
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?