用内容填充儿童DIV

时间:2016-03-08 18:34:13

标签: javascript

是否可以从DIV中删除 class =" con" ,将其处理为" child DIV"来自 lis 并将内容放入其中?

HTML:

<div class="lis" id="123">Title...<div class="con"></div></div>

JAVASCRIPT:

<script>

[].forEach.call(document.getElementsByClassName("lis"), function(elem) {
elem.addEventListener("click", function() {

 // get data via ajax

 this.getElementsByClassName("con")[0].innerHTML = data;

 });
})
</script>

所以看起来应该是这样的:

HTML:

<div class="lis" id="123">Title...<div></div></div>

JAVASCRIPT:

<script>

[].forEach.call(document.getElementsByClassName("lis"), function(elem) {
elem.addEventListener("click", function() {

 // get data via ajax

 // put the data into the child of this.id / lis DIV

 });
})
</script>

0 个答案:

没有答案