MCPcopy Create free account
hub / github.com/unconed/TermKit / findElement

Function findElement

HTML/external/syntaxhighlighter_3.0.83/src/shCore.js:487–511  ·  view source on GitHub ↗

* Looks for a child or parent node which has specified classname. * Equivalent to jQuery's $(container).find(".className") * @param {Element} target Target element. * @param {String} search Class name or node name to look for. * @param {Boolean} reverse If set to true, will go up the node tree i

(target, search, reverse /* optional */)

Source from the content-addressed store, hash-verified

485 * @return {Element} Returns found child or parent element on null.
486 */
487function findElement(target, search, reverse /* optional */)
488{
489 if (target == null)
490 return null;
491
492 var nodes = reverse != true ? target.childNodes : [ target.parentNode ],
493 propertyToFind = { '#' : 'id', '.' : 'className' }[search.substr(0, 1)] || 'nodeName',
494 expectedValue,
495 found
496 ;
497
498 expectedValue = propertyToFind != 'nodeName'
499 ? search.substr(1)
500 : search.toUpperCase()
501 ;
502
503 // main return of the found node
504 if ((target[propertyToFind] || '').indexOf(expectedValue) != -1)
505 return target;
506
507 for (var i = 0; nodes && i < nodes.length && found == null; i++)
508 found = findElement(nodes[i], search, reverse);
509
510 return found;
511};
512
513/**
514 * Looks for a parent node which has specified classname.

Callers 3

findParentElementFunction · 0.85
quickCodeHandlerFunction · 0.85
shCore.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected