Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#31 Find previous element by tag or attribute

Next_Release
open
nobody
Functions (11)
5
2012-10-10
2012-05-16
Anonymous
No

Same thing as find() just moving up the dom tree.

So, I could do something like:

Title

this is $myElem

$prevElem = $myElem->find_up('h2'); => Would give me Title
$prevElem = $myElem->find_up('div[class=myclass]'); Would give me

Thanks

Discussion

  • nickl-
    nickl-
    2012-09-11

    How is this different to find()? What are he benefits? I'm not seeing it.

     
  • John Schlick
    John Schlick
    2012-10-10

    This is partially implemented as find_ancestor_tag. It allows you to move up the dom tree and find the tag specifies as a parent of the current tag. It starts at line 330 in the code.

    If you expand it to use the full find syntax, I'd be happy to look at that patch. (you should use the parse_selector and match functions in your solution.