Skip to content

Querypath vs jQuery difference #17

@jakejackson1

Description

@jakejackson1

From querypath created by Jelle-S: technosophos/querypath#113

First of all, I love this library!

On the homepage of Querypath, the library is described as "jQuery for the server". And after using it a couple of times, that's exactly what it is!

But -and I don't think this is a real "issue"- I found a quite large difference with jQuery and I was wondering what the reason for this difference is (and I'm guessing it's performance and memory usage, but I just wanted to check to be sure).

Ok, so in jQuery you can do the following:

var $body = $('body');
// $body represents the body DOM element.
$body.find('div.changeme').text('I am changed');
// $body still represents the body DOM element.
var $some_element = $body
    .find('#footer')
    .find('#copyright')
    .find('.some-class')
    .find('.some-element');
// $body still represents the body DOM element.

If you do the same in Querypath, the $body variable would change constantly:

$body = qp('myhtmlpage.html')->find('body');
// $body represents the body DOM element.
$body->find('div.changeme')->text('I am changed'); 
// $body now represents div.changeme and we would need
// to call $body->end() for it to represent the body DOM
// element again.
$some_element = $body
    ->find('#footer')
    ->find('#copyright')
    ->find('.some-class')
    ->find('.some-element');
// $body now represents .some-element and we can only
// use $body->end() once, twice would result in an empty
// QueryPath object, so we can only go as far back as .some-class.

The alternative would be to clone $this on each call and set the matched elements on the cloned object and then returning the clone in stead of $this. I can imagine how that could be a memory issue, but I'd just like your thoughts on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions