Modify ↓
Ticket #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: | |
| Blocking: | Blocked by: |
Description
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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

This bug is invalid IMHO.
The reason for your problem has two main causes:
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/