javascript - 在其他 DIV(由其他类指定)中追加 DIV(由类指定)

标签 javascript jquery html append appendto

我有 HTML 工作表“A”和“B”。 (HTML 工作表“B”被读入 html 工作表“A”。“A”作为“B”中非常变化的内容的"template"。)

我在 HTML 工作表“A”中有这个 div

 <div class="productsheet-container">
 </div>

我将此 div 添加到 HTML 工作表“B”:

<div class="productsheet">
          hello
</div>

这是我要求的结果:

 <div class="productsheet-container">
      <div class="productsheet">
              hello
      </div>
 </div>

div class="productsheet" 应该从其原始位置隐藏。所以只在 div class="productsheet-container" 中可见。

如果有人能在这里帮助我,我将永远感激不已! 我确切地使用什么 JavaScript?笔记!我是 JavaScript 的 COMPLETE NEWB,一生中没有写过一行代码!所以,对我来说,我发现谷歌搜索的答案似乎不够。

例如,我试过:

$( ".productsheet-container" ).append( $( "<div class='productsheet' />" ) );

但我不应该在之前和/或之后也写点东西吗?

最佳答案

你可以只用 CSS 解决这个问题:

.productsheet{
    display:none;
}
.productsheet-container .productsheet{
    display:block;
}

演示 here

要完成第二部分,你可以使用这个:

$(".productsheet-container").append($('.productsheet'));

演示 here

关于javascript - 在其他 DIV(由其他类指定)中追加 DIV(由类指定),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18682425/

相关文章:

javascript - jQuery 替换 html 标签和链接之外的内容

javascript - 如何从连接回调之外的应用程序中的任何位置发出套接字?

javascript - 如何通过 openlayers 绘制矩形?

javascript - 根据按钮的点击增加隐藏输入的值

javascript - 我有办法在 slickgrid 标题中垂直对齐文本

javascript - 如何在 *ngFor 中获取 *ngIf 的第一个真值

javascript - 清除数组中的空元素

html - 无法让提交框显示在文本框下方

javascript - 如何将动画应用于元素直到滚动到它?

html - css - 当鼠标离开时将选择恢复到正常状态