Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#14840 closed bug (notabug)

$(elem).attr and elem.getAttribute get diffrent values

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

var a = $('<div data-a="abc"></div>')
a.data('a');			//abc
a.attr('data-a');		//abc
a[0].setAttribute('a', 'efg');
a.data('a');			//abc
a[0].getAttribute('a');	//efg
a.attr('data-a');		//efg

in the real word, i use a mvvm framework. The attr changes by the framework. i cant use $(elem).data() method to change the value, but i need to get the value.

Change History (3)

comment:1 Changed 5 years ago by anonymous

sorry,i get wrong test case.

var a = $('<div data-a="abc"></div>')
a.data('a');			//abc
a.attr('data-a');		//abc
a[0].setAttribute('data-a', 'efg');
a.data('a');			//abc
a[0].getAttribute('a');	//efg
a.attr('data-a');		//efg

$(elem).attr get the right value, $(elem).data get the different value

comment:2 Changed 5 years ago by dmethvin

Resolution: notabug
Status: newclosed

The documentation on .data() says that it gets the data- attributes once on first access.

comment:3 in reply to:  2 Changed 5 years ago by anonymous

Replying to dmethvin:

The documentation on .data() says that it gets the data- attributes once on first access.

thanks

Note: See TracTickets for help on using tickets.