admin管理员组文章数量:1024615
I've seen similar questions asked but I couldn't make it work for me with Knockout 'data-bind'
I have a parent div with some multiple divs inside. On the parent div I have a click event, that I do not want to fire on a specific child div that has some other event handling.
I have something like this:
<div class='parent' dataBind='click: parentClicked'>
<div class='child' dataBind='click: childClicked'></div>
....some other stuff...
</div>
In my view model I tried:
function parentClicked() {
alert('parent clicked');
}
function childClicked(event) {
alert('child clicked');
event.stopPropagation();
}
I get that 'event.stopPropagation()' is not a function.
What am I doing wrong?
I've seen similar questions asked but I couldn't make it work for me with Knockout 'data-bind'
I have a parent div with some multiple divs inside. On the parent div I have a click event, that I do not want to fire on a specific child div that has some other event handling.
I have something like this:
<div class='parent' dataBind='click: parentClicked'>
<div class='child' dataBind='click: childClicked'></div>
....some other stuff...
</div>
In my view model I tried:
function parentClicked() {
alert('parent clicked');
}
function childClicked(event) {
alert('child clicked');
event.stopPropagation();
}
I get that 'event.stopPropagation()' is not a function.
What am I doing wrong?
1 Answer
Reset to default 8You have to use clickBubble: false
. For reference: Preventing the event from bubbling
<div class='parent' dataBind='click: parentClicked'>
<div class='child' dataBind='click: childClicked, clickBubble: false'></div>
....some other stuff...
</div>
I've seen similar questions asked but I couldn't make it work for me with Knockout 'data-bind'
I have a parent div with some multiple divs inside. On the parent div I have a click event, that I do not want to fire on a specific child div that has some other event handling.
I have something like this:
<div class='parent' dataBind='click: parentClicked'>
<div class='child' dataBind='click: childClicked'></div>
....some other stuff...
</div>
In my view model I tried:
function parentClicked() {
alert('parent clicked');
}
function childClicked(event) {
alert('child clicked');
event.stopPropagation();
}
I get that 'event.stopPropagation()' is not a function.
What am I doing wrong?
I've seen similar questions asked but I couldn't make it work for me with Knockout 'data-bind'
I have a parent div with some multiple divs inside. On the parent div I have a click event, that I do not want to fire on a specific child div that has some other event handling.
I have something like this:
<div class='parent' dataBind='click: parentClicked'>
<div class='child' dataBind='click: childClicked'></div>
....some other stuff...
</div>
In my view model I tried:
function parentClicked() {
alert('parent clicked');
}
function childClicked(event) {
alert('child clicked');
event.stopPropagation();
}
I get that 'event.stopPropagation()' is not a function.
What am I doing wrong?
1 Answer
Reset to default 8You have to use clickBubble: false
. For reference: Preventing the event from bubbling
<div class='parent' dataBind='click: parentClicked'>
<div class='child' dataBind='click: childClicked, clickBubble: false'></div>
....some other stuff...
</div>
本文标签: javascriptKnockout JS prevent click event triggering on a specific childStack Overflow
版权声明:本文标题:javascript - Knockout JS prevent click event triggering on a specific child - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745610321a2158965.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论