http://device302.me

device302.me

information

Description »

明朝体なんでwinだとガビガビすかね。。。。

contents

post-id : 18065291660

February 22nd, 2012, 7:54:00

DOM -> jQuery objcet & jQuery object -> DOM

jQuery objectを普通のDOMエレメントとして使いたい時用のメモ
主に「やっぱここはaddEventListenerを使いてーなー」って時とか用

DOM -< jQuery object

$(document.body);

jQuery object -< DOM

$(document.body)[0] 


以下サンプル

html
  <span id="hoge">hoggehoge</span>
js
  $().ready(function(){
    var $hoge = $('#hoge');
    var _hoge = $hoge['0'];
    var hoge_fnc = function(e){ console.log(e.target); }
    
    $hoge.bind('click', hoge_fnc ); // OK
    _hoge.addEventListener('click', hoge_fnc, false); // OK
//    $hoge.addEventListener('click', hoge_fnc, false); // Error 'has no method addEventListener'
//    _hoge.bind('click', hoge_fnc ); // Error 'has no method bind'
  });

だからどうしたという話でもある。

が、実はとってもユースフル(わら

— written by device302