Bug Tracker

Modify

Ticket #6737 (closed bug: wontfix)

Opened 3 years ago

Last modified 2 years ago

.attr() does not return "undefined" in IE6/7 for an undefined attribute

Reported by: Beeper Owned by:
Priority: low Milestone: 1.4.3
Component: attributes Version: 1.4.2
Keywords: Cc:
Blocking: Blocked by:

Description

On an input-element i want to check an attribute for existence. so i have something like: $('#id').attr('src') !== undefined

Here is the working example for Jquery 1.3.2:  http://jsbin.com/oveci

Here is the Bug:  http://jsbin.com/oveci/3

It seems to apply only for some HTML-Elements. I tried 'p' and .attr works fine, but for input-elements it returns "" and not "undefined".

Change History

comment:1 Changed 3 years ago by dmethvin

For attributes that mirror properties on specific DOM elements, such as the checked attribute on a checkbox or radio button, .attr() will return a non-undefined value.

The best cross-browser way to approach this is to check for a falsy value using if ( $('#id').attr('src') ) rather than checking for a particular value.

comment:2 Changed 3 years ago by rwaldron

  • Keywords docfix added
  • Priority set to low
  • Status changed from new to closed
  • Resolution set to wontfix

This is not a bug, please see post by dmethvin

comment:3 Changed 3 years ago by snover

  • Keywords needsdocs added; docfix removed

comment:4 Changed 2 years ago by addyosmani

  • Keywords needsdocs removed

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.