Skip to content

Instantly share code, notes, and snippets.

@imanilchaudhari
Created October 9, 2018 09:42
Show Gist options
  • Save imanilchaudhari/e860e95da7fce1c7c460002c36e2c5fa to your computer and use it in GitHub Desktop.
Save imanilchaudhari/e860e95da7fce1c7c460002c36e2c5fa to your computer and use it in GitHub Desktop.
DOMElement getElementsByClass
<?php
public function getElementsByClass(&$parentNode, $tagName, $className)
{
$nodes = array();
$childNodeList = $parentNode->getElementsByTagName($tagName);
for ($i = 0; $i < $childNodeList->length; $i++) {
$temp = $childNodeList->item($i);
if (stripos($temp->getAttribute('class'), $className) !== false) {
$nodes[]=$temp;
}
}
return $nodes;
}
// source https://stackoverflow.com/questions/6366351/getting-dom-elements-by-classname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment