That i开发者_开发知识库s to say how can javascript find elements (eg. those with class 'foo') within a passed subset of the document ('context', in the jQuery example).
If context
is a DOM element, I believe that it inherits all of the document's DOM methods. For example:
jQuery('.foo', context)
..could be rewritten as:
context.getElementsByClassName('foo')
..so long as context
is a DOM element.
You can call someElem.getElementsByClassName
.
Note that it's not supported by IE.
The DOM method getElementsByClassName()
var elements = context.getElementsByClassName( 'foo' );
Just be aware of its browser support.
context.getElementsByClass('foo');
context.querySelectorAll('.foo');
For some reason, IE8 supports querySelectorAll, but only IE9 supports getElementsByClassName.
精彩评论