我正在尝试使用 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/