Bug Tracker

Opened 12 years ago

Closed 12 years ago

#7107 closed bug (invalid)

calling $(this).attr('children') returns blank list

Reported by: longears Owned by:
Priority: undecided Milestone: 1.4.3
Component: attributes Version: 1.4.2
Keywords: 'children' attribute Cc:
Blocked by: Blocking:


I have an element: <button class="delete" children="6">delete</button>

I have a click listener on the button: $('button.delete').live('click', deleteTask);

In my deleteTask() method I am unable to access the "children" attribute of my button: $(this).attr('children')

When Output $(this).attr('children') to the console it gives me this: []

This is the same behavior as if I were to try to output an attribute that doesn't exist.

Change History (2)

comment:1 Changed 12 years ago by jitter

This bug is invalid IMHO.

The reason for your problem has two main causes:

  • children is no valid html/xhtml attribute for button
  • children is (although not defined by any standard but available in all current browsers) a DOM attribute of the button element and holds all child element nodes of the button.

So when you call $(this).attr('children') jQuery accesses the DOM attribute and not the (invalid) HTML attribute and you get back an empty HTMLCollection.

If I may give you an advise don't use invalid attributes or at least choose a name which doesn't collide with existing DOM attributes.

Your are better off using jQuery data() to store custom data on element http://api.jquery.com/data/

comment:2 Changed 12 years ago by john

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.