Anyone even to detect when the Class attribute changes for a control

I have a div control with some id = "myDiv" class = "myClass" var var1 = 10; in user action based Javascript, I will change the class for this form of control "myClass" to "newClass", so when that happens I want to change the value of var1 to 20.

So, how would I recognize this change in the class.

Thanks in advance

0
source share
2 answers

You can use onpropertychange (IE) and DOMAttrModified (others)

0
source

You will need to use 3 things:

  • onpropertychange event , for IE <9
  • DOMAttrModified works in IE9, Opera, Firefox and, unfortunately, in all others , since Dr.Molle offers
  • Everything else - should resort to a setInterval loop , which checks if the value has changed, this includes webkit browsers (chrome and safari), since they still do not support DOMAttrModified, so - you should resort to checking the cycle for these browsers .

There is a jQuery plugin that implements this (there is also a demo on the page):

http://darcyclarke.me/dev/watch/

+2
source

Source: https://habr.com/ru/post/1393372/


All Articles