2016-09-27 86 views
-4

函數所以我有這樣的代碼:JQuery的。之前是無法在Chrome

var div = document.createElement('div'); 
var ad = document.getElementById('add');//where 'add' is a div with that id. 
ad.before(div); 

我的問題是,這是在Firefox工作正常,但在Chrome它說:

遺漏的類型錯誤:廣告.before不是功能

在此先感謝。

編輯:謝謝大家。我在jquery和js中非常新,以至於我甚至無法區分它們。

+3

您需要實際使用jQuery才能...才能使用jQuery。 –

+1

我認爲你應該通過https://learn.jquery.com/ – epascarello

回答

0

我想你需要一個DOM方法appendChild和insertBefore;

parentNode.insertBefore(newChild, refChild) 

您可以檢查documentations

0

您需要使用jQuery才能真正使用jQuery。

before文檔狀態:

This is an experimental technology Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

你要麼想insertBefore或實際使用jQuery。