javascript - 未捕获的类型错误 : undefined is not a function while using . prepend()

标签 javascript jquery

我正在尝试使用 jQuery <div class="myclass"></div> 将一个空 div ( .prepend() ) 添加到另一个 div 容器中但我一直遇到Uncaught TypeError: undefined is not a function 。以下是我到目前为止所拥有的。请对可能出现的问题提出任何建议?谢谢

我收到错误消息

TypeError: 'undefined' is not a function (evaluating '$$('#global_content').prepend($('<p>Test</p>'))')

HTML 代码和 JavaScript

<script type='text/javascript'>
window.addEvent('domready', function() {
$$('#global_content').prepend($('<p>Test</p>'));
});
</script>


<div id="global_content">
I want to add a div here above all other divs in this container using jQuery
  <div class="myclass1"></div>
   <div class="myclass2"></div>
   <div class="myclass3"></div>
  <div class="myclass4"></div>
</div>

最佳答案

这里有一个错误:

$$

在导致错误的选择器之前。

而不是:

<script type='text/javascript'>
window.addEvent('domready', function() {
$$('#global_content').prepend($('<p>Test</p>'));
});
</script>

做:

<script type='text/javascript'>
window.addEvent('domready', function() {
$('#global_content').prepend($('<p>Test</p>'));
});
</script>

关于javascript - 未捕获的类型错误 : undefined is not a function while using . prepend(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23272809/

相关文章:

jquery - 与 CSS 作斗争的艰难时期。无法获得背景图像下方的背景颜色

javascript - 使用canvas标签在html中添加谷歌地图

javascript - 显示来自所选单选按钮的自定义 HTML5 数据属性

javascript - 递归循环节点的子节点

Javascript:处理多个动态元素的事件

javascript - 为什么背景图像不使用 Angular 设置?

javascript - 如何在点击时重新加载 iframe?

jQuery水平动画而不是垂直动画

javascript - jQuery 单击/切换显示/隐藏 div 面板

javascript - jQuery 将自定义函数绑定(bind)到附加元素