Is it possible to access $(this)
and perform actions such as hide()
or toggle()
this div
in Knockout? I'm trying to access it via jQuery. Any alternative methods within the function is appreciated.
At the moment if I do this:
click: function(){ console.log(this) }
I get the $data
of my viewmodel.
I know other ways of handling this action via the model of knockout but I was wondering if this is possible?
<div data-bind="click: function(){ $(this).hide() }" class="alert alert-secondary alert-dismissible fade show" role="alert" >
some text here
</div>
It's almost always better to handle logic on the view-model instead of cluttering your markup, however, you can access the element with "$element" instead of "this". For a better example of how things should be done refer to Tomalak's excellent answer.