Skip to content

Instantly share code, notes, and snippets.

@Restoration
Last active October 14, 2016 05:34
Show Gist options
  • Select an option

  • Save Restoration/938c01c2e123b0bec4b5fdd7e2a5b084 to your computer and use it in GitHub Desktop.

Select an option

Save Restoration/938c01c2e123b0bec4b5fdd7e2a5b084 to your computer and use it in GitHub Desktop.

#jQuery.noConflict( [true/false] )

noConflictメソッドを実行するとjQueryを$と省略することができなくなる。
よって、他のプラグインと$が競合することを避けることができます

##同一ページ内でバージョンの異なるjQueryライブラリを読み込む方法

後から記述されたバージョンのライブラリが優先される 以下の場合だと、1.4.2が優先される

<script type="text/javascript" src="./js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="./js/jquery-1.4.2.min.js"></script>
//noCnflictを使用して$を使えなくする
<script type="text/javascript" src="./js/jquery.2.1.4.min.js"></script>
<script type="text/javascript">
    var j = jQuery.noConflict();// jQuery 2.1.4をjとして定義
</script>
<script type="text/javascript" src="./js/jquery-1.4.2.min.js"></script>

上記のコードにより2.1.4は$ではなくjとして定義されている
プラグインなどを使用するときはj('#hoge').fn.queryのように記述する。

公式マニュアル

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment