0

I have KO custom binding on an input element and need it to detect if there's been a change (or addition) of a css class for that element. Is this something I detect using a custom binding, or not?

1 Answer 1

2

It is usually not a good idea to mix Knockout and other methods to manipulate the DOM.

So in your case it is probably a better idea to set the CSS class using knockout maybe with a computed. See knockout js css multiple class bindings

If the class manipulation is outside your control (for example because it is done by an external plugin). Then you can use something like the Attr change jquery plugin to detect the DOM change and then set an observable with the result (which can then be detected by your custom binding)

Sign up to request clarification or add additional context in comments.

2 Comments

A commendable solution. To be more specific, I'm using KnockoutJS-Validation plug-in which adds an error class to the input field. I need to detect an invalid field and have this passed to the custom binding so I can run jQuery plug-in on that element. Any ideas appreciated pls - stackoverflow.com/questions/21405518/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.