smartdj / ganon

Automatically exported from code.google.com/p/ganon
0 stars 0 forks source link

$node what is that. #30

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
this is example code

from this wiki url : http://code.google.com/p/ganon/wiki/AccesElements

please let me know what is $node how to defined it.

thanks in advance.

    // To use a CSS selector query on a node, you simply use the node as a function.
    // The result will be stored in an array (of nodes).
    $match_array = $node('.myclass');

    // To iterate the result, you can use foreach
    foreach($match_array as $element) {
      echo $element, "<br>\n"; 
    }

    // The above can be shortened to the following
    foreach($node('.myclass') as $element) {
      echo $element, "<br>\n"; 
    }

    // Because $element is also a node, you can also perform a query on that node
    // and nest queries
    foreach($node('.myclass') as $element) {
      foreach($element('.myotherclass') as $new_element) {
        echo $new_element, "<br>\n"; 
      }
    }

    // If you know which element of the array you
    // are going to need, you can pass an index to the function
    $a = $node('a', 2);
    // A negative index will start counting from the end of the array
    $a = $node('a', -1);

Original issue reported on code.google.com by manojpal...@gmail.com on 4 Jan 2013 at 7:26

GoogleCodeExporter commented 9 years ago
That is a very good point, that should be added to the article! Sorry for the 
late response.

For further examples, you can see the repository: 
http://code.google.com/p/ganon/source/browse/#svn%2Ftrunk%2Fexamples

Original comment by niels....@gmail.com on 7 Apr 2013 at 2:59