gawel / pyquery

A jquery-like library for python
http://pyquery.rtfd.org/
Other
2.29k stars 182 forks source link

Different result about ":last" comparing jquery #167

Open kiddx01 opened 7 years ago

kiddx01 commented 7 years ago

html code here:

<!DOCTYPE html>
<html>
<head>
    <style>.highlight {
        background-color: yellow
    }</style>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
</head>

<body>
    <p>
        <span>Look:</span>
        <span>This is some text in a paragraph.</span>
        <span>This is a note about it.</span>
    </p>
    <p>
        <span>Look:</span>
        <span>This is some text in a paragraph.</span>
        <span>This is a note about it.</span>
    </p>
    <p>
        <span>Look:</span>
        <span>This is some text in a paragraph.</span>
        <span>This is a note about it.</span>
    </p>
</body>
</html>

jquery

code

<script>$("p span:last").addClass('highlight');</script>

result: This is a note about it.

code:

<script>$("span:last").addClass('highlight');</script>

a same rsult This is a note about it.

pyquery

code:

html("p span:last").text()
#  'This is a note about it. This is a note about it. This is a note about it.'

html("span:last").text()
#  'This is a note about it.'

why the behavior of pyquery is different with jquery ? pyquery version: 1.2.17

gawel commented 6 years ago

because pyquery is not jQuery. It's hard to get the exact same behavior. Feel free to try to fix this one... :)