PHP Classes

File: classes/css-parser/filters/css-pseudo-nth-child-filter.php

Recommend this page to a friend!
  Classes of Gonzalo Chumillas   PHP CSS Parser   classes/css-parser/filters/css-pseudo-nth-child-filter.php   Download  
File: classes/css-parser/filters/css-pseudo-nth-child-filter.php
Role: Class source
Content type: text/plain
Description: CSSPseudoNthChildFilter class
Class: PHP CSS Parser
Get HTML document nodes matching a CSS selector
Author: By
Last change: Merge branch 'master' of https://github.com/cequiel/cssparser
update
Date: 10 years ago
Size: 823 bytes
 

Contents

Class file image Download
<?php
require_once dirname(dirname(__DIR__)) . "/css-parser/css-helper.php";
require_once
dirname(dirname(__DIR__)) . "/css-parser/filters/css-filter.php";

class
CSSPseudoNthChildFilter extends CSSPseudoFilter {
   
/**
     * Sibling position.
     * @var int
     */
   
private $position;
   
   
/**
     * @param int $position
     */
   
public function __construct($position) {
       
$this->position = $position;
    }
   
   
/**
     * Does the node match?
     * @param DOMElement $node
     * @return boolean
     */
   
public function match($node) {
       
$i = 1;
       
        while (
$node = CSSHelper::getPreviousSiblingElement($node)) {
           
$i++;
            if (
$i > $this->position) {
                return
FALSE;
            }
        }
        return (
$i == $this->position);
    }
}