# jQueryに独自の関数を追加

- リンク: https://torounit.com/blog/jquery%e3%81%ab%e7%8b%ac%e8%87%aa%e3%81%ae%e9%96%a2%e6%95%b0%e3%82%92%e8%bf%bd%e5%8a%a0/
- 公開日: 2011-05-30T14:16:24+09:00
- 作成者: Toro\_Unit

jQueryを使っているとやっぱり独自の関数を作りたくなってきますよね。

hoge()とhogehoge()というjQueryで使える関数を作ります。

[js]
 jQuery.fn.extend({ hoge:function(vars){ jQuery(this).addClass("hoge").css({
color:"#FFF"}); return this; }, hogehoge:function(){ var $this = jQuery(this); $
this.html("hogehoge"); return this; } }); [/js]

こんな感じで独自の関数を定義できます。コードの再利用が簡単になるので、覚えておい
て損はないです。
 return thisを返しておくと、メソッドチェーンができるようになるので、
忘れずに入れましょう。
