-
{element}.onclick = function(event) {
if (!event) event = window.event;
var target = (event.target) ? event.target : event.srcElement;
...
};
*
to query the DOM in CSS-selector style
function getNextElement(node) {
if(node.nodeType == 1) {
return node;
}
if (node.nextSibling) {
return getNextElement(node.nextSibling);
}
return null;
}
var container = document.getElementById('container');
or
var container = document.querySelector('#container');
or
$('#container')
var lis = document.getElementById('container').getElementsByTagName('li');
or
var lis = document.querySelectorAll('#container li');
or
$('#container').find('li')
var anchors = document.getElementsbyTagName('a');
addEvent(anchors, 'click', fn);
or
[].forEach.call( document.querySelectorAll('a'), function(el) {
el.addEventListener('click', function() {
// anchor was clicked
}, false);
});
or
$('a').on('click', fn);
var uls = document.getElementsByTagName('ul');
addEvent(uls, 'click', function(e) {
var target = e.target || e.srcElement;
/*
or var target = (e.target) ? e.target : e.srcElement;
*/
if ( target && target.nodeName === 'A' ) {
// proceed
}
});
or
document.addEventListener('click', function(e) {
if ( e.target.matchesSelector('ul a') ) {
// proceed
}
}, false);
/*
or
var matches;
(function(doc) {
matches =
doc.matchesSelector ||
doc.webkitMatchesSelector ||
doc.mozMatchesSelector ||
doc.oMatchesSelector ||
doc.msMatchesSelector;
})(document.documentElement);
document.addEventListener('click', function(e) {
if ( matches.call( e.target, 'ul a') ) {
// proceed
}
}, false);
*/
or
$('ul').on('click', 'a', fn);
*
<em />
c.f. <i />
<strong />
c.f. <b />
<abbr />
<sup />
*
<label />
<href />
<img />
*.gif, *.jpeg or *.jpg
* 페이지 머리글
<h1>..</h1>
* 블록 인용문
<blockquote />
.cite
* 목록
<ul>
<li>..</li>
<li>..</li>
..
</ul>
<ol />
<li />
* 테이블
<table summary=".." border="1">
<caption>..</caption>
<tr>
<th>..</th>
<th>..</th>
..
</tr>
<tr>
<td>..</td>
<td>..</td>
..
</tr>
..
</table>
참조 사이트:
http://net.tutsplus.com/tutorials/javascript-ajax/from-jquery-to-javascript-a-reference/
http://jjjryu.tistory.com/entry/HTML