sourcebitsllc / chocolatechip-ui

Mobile Web App Framework
www.chocolatechip-ui.com
MIT License
616 stars 88 forks source link

.find() throws "has no method querySelectorAll' if there is a text element #20

Closed extrakun closed 10 years ago

extrakun commented 10 years ago

If I try the following line in console:

$('<p class="test">hello world</p>   <p>hi!</p>').find(".test")

I will get:

TypeError: Object #<Text> has no method 'querySelectorAll'

What's the best way to fix this issue?

sourcebits-robertbiggs commented 10 years ago

I'm not sure why you have the white space there. That will create an empty text node. A text node does not support querySelector or querySelectorAll. This will work without problem. $('<p class="test">hello world</p><p>hi!</p>').find(".test").find('.test')

sourcebits-robertbiggs commented 10 years ago

This has been resolved with commit c0ad390624 The $.make method will not strip out any empty white space from nodes. However, it will leave text nodes with content.