英文:
Click even on button not Working if it has a span inside ( it works only when i click near border ) JS
问题
<button class="anunt-edit" type="submit" data-id="@anunt.Id" id="editButton" >
@Html.Partial("editSVGPartial", new {@Id="editButton", @class="svg"})
</button>
The Html Helper partial is for an Edit icon span,
the problem is that in javascript e.target.matches("#editButton") returns true only when i click the button near border ( i think it doesnt work properly because of the span that is inside )
document.addEventListener("click", e =>
{
var isEditButtonClicked = e.target.matches("#editButton");
if ( isEditButtonClicked )
{
console.log("button clicked")
}
else
{
console.log("click")
}
})
英文:
<button class="anunt-edit" type="submit" data-id="@anunt.Id" id="editButton" >
@Html.Partial("editSVGPartial", new {@Id="editButton", @class="svg"})
</button>
The Html Helper partial is for an Edit icon span,
the problem is that in javascript e.target.matches("#editButton") returns true only when i click the button near border ( i think it doesnt work properly because of the span that is inside )
document.addEventListener("click", e =>
{
var isEditButtonClicked = e.target.matches("#editButton");
if ( isEditButtonClicked )
{
console.log("button clicked")
}
else
{
console.log("click")
}
})
答案1
得分: 1
我将 span 的 id 更改为与其直接父级按钮的 id 相同,现在它可以正常工作。
英文:
I changed the id of the span to the same one as the id of the button that is the direct parent and now it works.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论