Bug Tracker

Modify

Ticket #2119 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

attr('value') confusion

Reported by: arrix Owned by:
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.1
Keywords: Cc:
Blocking: Blocked by:

Description

I'm not sure whether this is a bug, it is confusing however.

<div id="div1" value="the value"></div>

$('#div1').attr('value') //=> undefined

In html, property and attribute are usually equivalent and the terms are often used interchangeably. So I think jquery is doing the right thing.

Change History

comment:1 Changed 5 years ago by serializer

The attr() function gets and sets (X)HTML attributes (as opposed to CSS).

However, your browser will only parse attributes if they are valid (for your DOCTYPE).

Since there is no 'value' attribute for <div> elements, you markup is invalid, and therefore the browser reports the attr as undefined. This is expected behaviour.

$('input').attr('value') might give you something more useful, since inputs do have a value attribute.

comment:2 Changed 5 years ago by flesler

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

Fixed at [5574], check #2548.

comment:3 Changed 5 years ago by flesler

  • Milestone changed from 1.2.2 to 1.2.4

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.