0

I am trying to use the following on an Ajax success:

$('#FormContent').data('seq',data.seqMod);

However, it does not work.

When I do alert(data.seqMod); it returns the correct value fine and the alert message has my integer in it (5) in this case.

Am I doing something wrong?

Thanks

realtek
  • 831
  • 4
  • 16
  • 36
  • 1
    JQuery caches `.data()` values internally, it doesn't update the attribute. – Barmar Jun 22 '16 at 20:38
  • thank you, so the HTML tag does not get updated, correct? – realtek Jun 22 '16 at 20:40
  • 1
    The DOM element attribute doesn't get updated, correct. – Barmar Jun 22 '16 at 20:41
  • Thanks Barmar, I just output the same data attribute using a getter and it is indeed working. I will see if .attr does instead. Cheers – realtek Jun 22 '16 at 20:43
  • You just have to be consistent. If you set with `.attr()`, read with `.attr()`. If you set with `.data()`, read with `.data()`. – Barmar Jun 22 '16 at 20:43
  • The only relationship between `.data()` and the attribute is the first time you read the data, it will initialize from the attribute. After that, they're not connected. – Barmar Jun 22 '16 at 20:44

0 Answers0