Skip to content

API Elements

Jaeger edited this page Oct 9, 2017 · 4 revisions

Based on phpQuery,see: phpQuery Wiki or jQuery Documentation

Table of Contents

QL\Dom\Elements

Class Elements

  • Class name: Elements
  • Namespace: QL\Dom
Examples

Traversing:

$queryList = QL\QueryList::get('https://github.com');

$queryList->find('a')->attr('href', 'newVal')->removeClass('className')->html('newHtml')->...

$queryList->find('div > p')->add('div > ul')->filter(':has(a)')->find('p:first')->nextAll()->andSelf()->...

$queryList->find('div.old')->replaceWith( $ql->find('div.new')->clone() )->appendTo('.trash')->prepend('Deleted')->...

GitHub login form:

$form = QueryList::get('https://github.com/login')->find('form');

$form->find('input[name=login]')->val('github user');
$form->find('input[name=password]')->val('github password');

$data = $form->serialize();
print_r($data);

$data = $form->serializeArray();
print_r($data);

Properties

[HTML Attributes]

//Gets the link address of the first image
$queryList->find('img')->src;
//equivalence
$queryList->find('img:eq(0)')->src;
//equivalence
$queryList->find('img')->eq(0)->src;

//Gets the abc attribute of the first image
$queryList->find('img')->abc;
//Gets the alt attribute of the second image
$queryList->find('img')->eq(1)->alt;
//equivalence
$queryList->find('img:eq(1)')->alt;

Methods

__construct

mixed QL\Dom\Elements::__construct($elements)

Elements constructor.

  • Visibility: public
Arguments
  • $elements mixed

map

\Illuminate\Support\Collection QL\Dom\Elements::map($callback)

Iterating elements

  • Visibility: public
Arguments
  • $callback mixed
Examples
$data = $queryList->find('img')->map(function($item){
    return $item->alt;
});
print_r($data->all());

attrs

\Illuminate\Support\Collection QL\Dom\Elements::attrs($attr)

Gets the attributes of all the elements

  • Visibility: public
Arguments
  • $attr mixed - <p>HTML attribute name</p>
Examples
// Get all the picture links
$data = $queryList->find('img')->attrs('src');
print_r($data->all());

texts

\Illuminate\Support\Collection QL\Dom\Elements::texts()

Gets the text of all the elements

  • Visibility: public

htmls

\Illuminate\Support\Collection QL\Dom\Elements::htmls()

Gets the html of all the elements

  • Visibility: public
Examples
$data = $queryList->find('#one')->append('<div>append content</div>')->find('div')->htmls();
print_r($data->all());

getElements

\phpQueryObject QL\Dom\Elements::getElements()
  • Visibility: public

toReference

 QL\Dom\Elements::toReference()
  • Visibility: public

documentFragment

 QL\Dom\Elements::documentFragment()
  • Visibility: public

toRoot

 QL\Dom\Elements::toRoot()
  • Visibility: public

getDocumentIDRef

 QL\Dom\Elements::getDocumentIDRef()
  • Visibility: public

getDocument

 QL\Dom\Elements::getDocument()
  • Visibility: public

getDOMDocument

 QL\Dom\Elements::getDOMDocument()
  • Visibility: public

getDocumentID

 QL\Dom\Elements::getDocumentID()
  • Visibility: public

unloadDocument

 QL\Dom\Elements::unloadDocument()
  • Visibility: public

isHTML

 QL\Dom\Elements::isHTML()
  • Visibility: public

isXHTML

 QL\Dom\Elements::isXHTML()
  • Visibility: public

isXML

 QL\Dom\Elements::isXML()
  • Visibility: public

serialize

 QL\Dom\Elements::serialize()
  • Visibility: public

serializeArray

 QL\Dom\Elements::serializeArray()
  • Visibility: public

get

 QL\Dom\Elements::get()
  • Visibility: public

getString

 QL\Dom\Elements::getString()
  • Visibility: public

getStrings

 QL\Dom\Elements::getStrings()
  • Visibility: public

newInstance

 QL\Dom\Elements::newInstance()
  • Visibility: public

find

 QL\Dom\Elements::find()
  • Visibility: public

is

 QL\Dom\Elements::is()
  • Visibility: public

filterCallback

 QL\Dom\Elements::filterCallback()
  • Visibility: public

filter

 QL\Dom\Elements::filter()
  • Visibility: public

load

 QL\Dom\Elements::load()
  • Visibility: public

trigger

 QL\Dom\Elements::trigger()
  • Visibility: public

triggerHandler

 QL\Dom\Elements::triggerHandler()
  • Visibility: public

bind

 QL\Dom\Elements::bind()
  • Visibility: public

unbind

 QL\Dom\Elements::unbind()
  • Visibility: public

change

 QL\Dom\Elements::change()
  • Visibility: public

submit

 QL\Dom\Elements::submit()
  • Visibility: public

click

 QL\Dom\Elements::click()
  • Visibility: public

wrapAllOld

 QL\Dom\Elements::wrapAllOld()
  • Visibility: public

wrapAll

 QL\Dom\Elements::wrapAll()
  • Visibility: public

wrapAllPHP

 QL\Dom\Elements::wrapAllPHP()
  • Visibility: public

wrap

 QL\Dom\Elements::wrap()
  • Visibility: public

wrapPHP

 QL\Dom\Elements::wrapPHP()
  • Visibility: public

wrapInner

 QL\Dom\Elements::wrapInner()
  • Visibility: public

wrapInnerPHP

 QL\Dom\Elements::wrapInnerPHP()
  • Visibility: public

contents

 QL\Dom\Elements::contents()
  • Visibility: public

contentsUnwrap

 QL\Dom\Elements::contentsUnwrap()
  • Visibility: public

switchWith

 QL\Dom\Elements::switchWith()
  • Visibility: public

eq

 QL\Dom\Elements::eq()
  • Visibility: public

size

 QL\Dom\Elements::size()
  • Visibility: public

length

 QL\Dom\Elements::length()
  • Visibility: public

count

 QL\Dom\Elements::count()
  • Visibility: public

end

 QL\Dom\Elements::end()
  • Visibility: public

_clone

 QL\Dom\Elements::_clone()
  • Visibility: public

replaceWithPHP

 QL\Dom\Elements::replaceWithPHP()
  • Visibility: public

replaceWith

 QL\Dom\Elements::replaceWith()
  • Visibility: public

replaceAll

 QL\Dom\Elements::replaceAll()
  • Visibility: public

remove

 QL\Dom\Elements::remove()
  • Visibility: public

markup

 QL\Dom\Elements::markup()
  • Visibility: public

markupOuter

 QL\Dom\Elements::markupOuter()
  • Visibility: public

html

 QL\Dom\Elements::html()
  • Visibility: public

xml

 QL\Dom\Elements::xml()
  • Visibility: public

htmlOuter

 QL\Dom\Elements::htmlOuter()
  • Visibility: public

xmlOuter

 QL\Dom\Elements::xmlOuter()
  • Visibility: public

php

 QL\Dom\Elements::php()
  • Visibility: public

markupPHP

 QL\Dom\Elements::markupPHP()
  • Visibility: public

markupOuterPHP

 QL\Dom\Elements::markupOuterPHP()
  • Visibility: public

children

 QL\Dom\Elements::children()
  • Visibility: public
Examples
//Get all the img child nodes under the class for two elements
$data = $ql->find('.two')->children('img')->attrs('alt');
print_r($data->all());
//Get the class for all child nodes under the two elements
$data = $ql->find('.two')->children()->map(function ($item){
    //Use is to determine the node type
    if($item->is('a')){
        return $item->text();
    }elseif($item->is('img'))
    {
        return $item->alt;
    }
});
print_r($data->all());

ancestors

 QL\Dom\Elements::ancestors()
  • Visibility: public

append

 QL\Dom\Elements::append()
  • Visibility: public

appendPHP

 QL\Dom\Elements::appendPHP()
  • Visibility: public

appendTo

 QL\Dom\Elements::appendTo()
  • Visibility: public

prepend

 QL\Dom\Elements::prepend()
  • Visibility: public

prependPHP

 QL\Dom\Elements::prependPHP()
  • Visibility: public

prependTo

 QL\Dom\Elements::prependTo()
  • Visibility: public

before

 QL\Dom\Elements::before()
  • Visibility: public

beforePHP

 QL\Dom\Elements::beforePHP()
  • Visibility: public

insertBefore

 QL\Dom\Elements::insertBefore()
  • Visibility: public

after

 QL\Dom\Elements::after()
  • Visibility: public

afterPHP

 QL\Dom\Elements::afterPHP()
  • Visibility: public

insertAfter

 QL\Dom\Elements::insertAfter()
  • Visibility: public

insert

 QL\Dom\Elements::insert()
  • Visibility: public

index

 QL\Dom\Elements::index()
  • Visibility: public

slice

 QL\Dom\Elements::slice()
  • Visibility: public

reverse

 QL\Dom\Elements::reverse()
  • Visibility: public

text

 QL\Dom\Elements::text()
  • Visibility: public

plugin

 QL\Dom\Elements::plugin()
  • Visibility: public

extend

 QL\Dom\Elements::extend()
  • Visibility: public

_next

 QL\Dom\Elements::_next()
  • Visibility: public

_prev

 QL\Dom\Elements::_prev()
  • Visibility: public

prev

 QL\Dom\Elements::prev()
  • Visibility: public

prevAll

 QL\Dom\Elements::prevAll()
  • Visibility: public

nextAll

 QL\Dom\Elements::nextAll()
  • Visibility: public

siblings

 QL\Dom\Elements::siblings()
  • Visibility: public

not

 QL\Dom\Elements::not()
  • Visibility: public

add

 QL\Dom\Elements::add()
  • Visibility: public

parent

 QL\Dom\Elements::parent()
  • Visibility: public

parents

 QL\Dom\Elements::parents()
  • Visibility: public

stack

 QL\Dom\Elements::stack()
  • Visibility: public

attr

 QL\Dom\Elements::attr()
  • Visibility: public

attrPHP

 QL\Dom\Elements::attrPHP()
  • Visibility: public

removeAttr

 QL\Dom\Elements::removeAttr()
  • Visibility: public

val

 QL\Dom\Elements::val()
  • Visibility: public

andSelf

 QL\Dom\Elements::andSelf()
  • Visibility: public

addClass

 QL\Dom\Elements::addClass()
  • Visibility: public

addClassPHP

 QL\Dom\Elements::addClassPHP()
  • Visibility: public

hasClass

 QL\Dom\Elements::hasClass()
  • Visibility: public

removeClass

 QL\Dom\Elements::removeClass()
  • Visibility: public

toggleClass

 QL\Dom\Elements::toggleClass()
  • Visibility: public

_empty

 QL\Dom\Elements::_empty()
  • Visibility: public

each

 QL\Dom\Elements::each()
  • Visibility: public

callback

 QL\Dom\Elements::callback()
  • Visibility: public

data

 QL\Dom\Elements::data()
  • Visibility: public

removeData

 QL\Dom\Elements::removeData()
  • Visibility: public

rewind

 QL\Dom\Elements::rewind()
  • Visibility: public

current

 QL\Dom\Elements::current()
  • Visibility: public

key

 QL\Dom\Elements::key()
  • Visibility: public

next

 QL\Dom\Elements::next()
  • Visibility: public

valid

 QL\Dom\Elements::valid()
  • Visibility: public

offsetExists

 QL\Dom\Elements::offsetExists()
  • Visibility: public

offsetGet

 QL\Dom\Elements::offsetGet()
  • Visibility: public

offsetSet

 QL\Dom\Elements::offsetSet()
  • Visibility: public

offsetUnset

 QL\Dom\Elements::offsetUnset()
  • Visibility: public

whois

 QL\Dom\Elements::whois()
  • Visibility: public

dump

 QL\Dom\Elements::dump()
  • Visibility: public

dumpWhois

 QL\Dom\Elements::dumpWhois()
  • Visibility: public

dumpLength

 QL\Dom\Elements::dumpLength()
  • Visibility: public

dumpTree

 QL\Dom\Elements::dumpTree()
  • Visibility: public

dumpDie

 QL\Dom\Elements::dumpDie()
  • Visibility: public