Skip to main content

Bug Tracker

Side navigation

#14840 closed bug (notabug)

Opened March 03, 2014 12:52PM UTC

Closed March 03, 2014 03:32PM UTC

Last modified March 04, 2014 02:59AM UTC

$(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.

Attachments (0)
Change History (3)

Changed March 03, 2014 01:16PM UTC by anonymous comment:1

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

Changed March 03, 2014 03:32PM UTC by dmethvin comment:2

resolution: → notabug
status: newclosed

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

Changed March 04, 2014 02:59AM UTC by anonymous comment:3

Replying to [comment:2 dmethvin]:

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

thanks