Google Groups Home
Help | Sign in
jQuery.delegate and selectors with spaces
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Toby  
View profile
 More options 1 Jul, 15:35
From: Toby <toby.hethering...@gmail.com>
Date: Tue, 1 Jul 2008 07:35:32 -0700 (PDT)
Local: Tues 1 Jul 2008 15:35
Subject: jQuery.delegate and selectors with spaces
Hello. I like $.delegate but it doesn't quite work the way I'd expect.
I need to use sudara's fork to get it to work at all, but even then I
have trouble whenever I use a selector containing a space. I've looked
at the source and can't see what the problem is.

Here's a test case. The animals div works the way I want. Click on the
Animals h2 to raise an 'h2' alert; Dog or Otter to raise an 'li'
alert.

For the fruits div, I've changed the 'li' selector to 'ul li'. I would
think that this should not change the behaviour, but now all clicks in
the div go to the 'ul li' handler, easily seen if you click the Fruits
h2.

<html>
<head>
        <script src="jquery.js" type="text/javascript" charset="utf-8"></
script>
        <script src="lowpro.jquery.js" type="text/javascript"
charset="utf-8"></script>
        <script type="text/javascript" charset="utf-8">
         $(function() {
           $('#animals').click($.delegate({
             'li': function (e) { alert('li'); },
             'h2': function (e) { alert('h2'); }
           }));
           $('#fruits').click($.delegate({
             'ul li': function (e) { alert('li'); },
             'h2': function (e) { alert('h2'); }
           }));
         });
        </script>
</head>
<body>
        <div id="animals">
                <h2>Animals</h2>
                <ul>
                        <li>Dog</li>
                        <li>Otter</li>
                </ul>
        </div>
        <div id="fruits">
                <h2>Fruits</h2>
                <ul>
                        <li>Apple</li>
                        <li>Durian</li>
                </ul>
        </div>
</body>
</html>


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google