jquery - 如何在不使用 html 的情况下将元素包含在 div 中?

标签 jquery html css dom parent

如果我的问题含糊不清或不清楚,我很抱歉,因为我对其中一些语言还比较陌生。

好的,我将解释一下情况:我目前有一个用 css 和 javascript 编写的音乐播放器,但是我想将所有这些“音乐播放器”放在我的 html 页面内的“内容”div 中。我在互联网上搜索了一下,发现您实际上无法更改 css 中的父 div(抱歉,如果我错了或使用了错误的术语)但是,它可以通过 jquery 和 DOM 来完成吗?我只是想知道这样做到底是如何做的,这是最好的方法吗?无论如何,为了帮助形象化情况,我将对我所做的事情做一个非常基本的模板。请记住,音乐播放器本身目前可以正常工作,我真的不想移动和更改所有 CSS。

HTML

<head>
<script type="text/javascript">
    $(document).ready(function(){
    var description = " description blah blah "

    $('body').Musicplayer(playlist, {
          autoplay:true,
          description:description,
          Player:{
              swfPath:'../plugin/jquery-mplayer'
    }
    });
    });
    </script>
</head>
<body>
<div id="content"> 
    <!-- this is where i want the musicplayer to be --> 
    content blah blah </div>
<!-- this is where it appears at the moment when i inspect the page in mozilla firefox -->
</body>

CSS

.Musicplayer {
    z-index:100;
    etc etc other stuff 
}

最佳答案

我想音乐播放器附加到 body 因为那是您传递给方法/函数的选择器。如果您只是将选择器修改为 $('#content') 那么它应该出现在 #content 元素中,所以我建议:

$('#content').Musicplayer(playlist, {
      autoplay:true,
      description:description,
      Player:{
          swfPath:'../plugin/jquery-mplayer'
    }
});

关于jquery - 如何在不使用 html 的情况下将元素包含在 div 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11849128/

相关文章:

html - 自定义 Font Awesome CSS

javascript - 非 webkit 浏览器,旋转 div 中相邻图像之间的间隙

jquery - 使用谷歌地图 API v3

javascript - 如何在没有任何循环语句的情况下获取数组中多个文件的值

ios - 如何将事件从在 UIWebView 中运行的 HTML 发送到 native Objective-C 代码?

jquery - 将来自输入的所有数据价格与 jquery 中可用的属性相加

html - 粘滞位置不是 'pushing' 其他粘滞元素

javascript - 为什么文字会压低图片?

jquery - 使用 Materialize CSS Select 组件的 VueJS 2 不会激活更改事件

javascript - Petfinder ajax 请求与 JSON 数组值问题