jQuery:获取具有特定 ID 的子对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3913891/
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: Get Child object with specific ID
提问by Bigbohne
First some HTML:
首先是一些 HTML:
<div id="tmcl-request" class="tmcl-request" style="display: none">
Request:
<b> Node: </b><span id="node">33947</span>
</div>
Than some JavaScript:
比一些 JavaScript:
$request = $('#tmcl-request');
$newrequest = $request.clone();
And now the question: I want to change the inner HTML of the <span id="node">
from the $newrequest
object.
而现在的问题是:我想要的内部HTML改变<span id="node">
从$newrequest
对象。
How to do this?
这该怎么做?
Thanks, Bigbohne
谢谢,比格博尼
回答by EMMERICH
$('#tmcl-request').find('#node').html('whatever you want your html to be');
Thought, if you will have multiple nodes it's better to use a class instead of an id, so
想,如果你有多个节点,最好使用一个类而不是一个 id,所以
$newrequest.find('#node').html('your html');