Jquery 将内容附加到 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16378203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery append content to div
提问by user2322509
I load a content to <div id="wrapper"></div>
via jquery.
我<div id="wrapper"></div>
通过 jquery加载内容。
$('#wrapper').html(data);
When the content inserted into wrapper, there is another div with id="video1"
.
当内容插入包装器时,还有另一个带有id="video1"
.
How can I append something to that id="video1"
我怎么能在上面附加一些东西 id="video1"
回答by pala?н
$('#video1').append('<p>Test</p>');
For demo, I have appended p
here.
对于演示,我已p
在此处附加。
回答by Benjamin Gruenbaum
Here is a working fiddle
这是一个工作小提琴
You can find the div by its ID in 'wrapper' after you insert it using .find
使用插入后,您可以在“包装器”中通过其 ID 找到该 div .find
$('#wrapper').html(data).find("#video1").append(<Your Data Here>);
回答by Anoop
$('#wrapper').html(data);
$('#video1').html("new data");
回答by bipen
try this,
尝试这个,
$('#wrapper').find('#video1').append('thingsYouWant');
OR
或者
$('#wrapper').html(data);
$('#video1').append('thingsYouWant');
you can directly use id selector to get the element after the element is added to the DOM
元素添加到DOM后可以直接使用id选择器获取元素
回答by San Tosh
This would definitely work:
这肯定会奏效:
$('#wrapper').html(
$('<div>').attr({'id':'video1'})
);
回答by Aleksandar Knezevic
Apparently, it is not possible to add something dynamically, e.g. content, to something that is considered static (as to my knowledge, could be wrong).
显然,不可能动态地添加一些东西,例如内容,到被认为是静态的东西(据我所知,可能是错误的)。
So, either you write it manually or you make some sort of automatisation...meaning JS for example.
因此,要么您手动编写它,要么进行某种自动化……例如 JS。
So, the answer would be no, to all those questions/question.
因此,对于所有这些问题/问题,答案是否定的。
Regards
问候