#160 ✓resolved
Douwe M.

Element#subNodes() major bug

Reported by Douwe M. | 2010-01-06 00:57:24 UTC | in 1.5.3 Release

Using Element#subNodes() with a css_rule always returns the firstChild if it has a tagName (i.e. isn't whitespace), plus the childs matching the css_rule, not only those matching the given css_rule.

This code for example, returns [<div id=​"a">​, <div id=​"b">​]:

    $E('div').insert(

    $E('div', {id: 'a'})
).insert(
    $E('div', {id: 'b'})
).subNodes('#b');</code>



While it should of course return [<div id="b">], because only this child matches the given css_rule.

Comments and changes to this ticket

  • MadRabbit

    MadRabbit 2010-01-06 01:04:44 UTC

    1. did you put your element on the page before the select?
    2. which browser is that?
  • Douwe M.

    Douwe M. 2010-01-06 01:08:45 UTC

    1) What exactly do you mean?
    2) This is Safari (so probably Chrome too), but looking at the code for Element#subNodes() it think it behaves like this in every browser (that you can count on, i.e. not IE). Haven't checked Firefox yet.

  • Douwe M.

    Douwe M. 2010-01-06 01:28:56 UTC

    Fixed version, called Element#subNodes2() (edited the line starting with return)

          Element.addMethods({

        subNodes2: function(css_rule) {
          var first_child = this.firstChild;
          return first_child ? ((first_child.tagName &amp;&amp; first_child.match(css_rule)) ? [$(first_child)] : []
            ).concat(this.rCollect.call(first_child, 'nextSibling', css_rule)) : [];
        },
      });</code>
    
    
    
    
  • MadRabbit

    MadRabbit 2010-01-08 17:33:16 UTC

    • Tag changed from “bug, element#subnodes” to “bug, element”
    • State changed from “new” to “resolved”

    pushed the fix on the server

  • MadRabbit

    MadRabbit 2010-01-10 14:07:05 UTC

    • Milestone set to “1.5.3 Release”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

RightJS Core Tickets

Shared Ticket Bins

People watching this ticket

Tags

Pages