Bug Tracker

Modify

Ticket #7107 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

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

comment:1 Changed 4 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 4 years ago by john

  • Status changed from new to closed
  • Resolution set to invalid

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.