英文:
this.sibling is undefiend why is it happening
问题
I've been sitting here and searching for multiple explanations of why it's not working but I can't figure it out. Why is it undefined?
I want number 55 or 45 to be alerted depending on which I click, but it won't do it.
英文:
I've been sitting here and searching for multiple explenations of why it's not working but i cant figure it out. Why is it undefiend?
I want number 55 or 45 to be alerted depending on which I click, but it wont do it.
<div class="antal">
<i class="fa fa-minus-circle" aria-hidden="true"></i><h2 class="bidbutton">55</h2>
<i class="fa fa-plus-circle" aria-hidden="true"></i>
</div>
<div class="antal">
<i class="fa fa-minus-circle" aria-hidden="true"></i><h2 class="bidbutton">45</h2>
<i class="fa fa-plus-circle" aria-hidden="true"></i>
</div>
$(".fa-plus-circle").click(function(){
alert($(this).siblings('.bidbutton').innerHTML);
});
答案1
得分: 0
因为jQuery对象没有名为innerHTML
的属性。HTML元素有:
alert($(this).siblings('.bidbutton')[0].innerHTML);
或者你可以在jQuery对象上使用.html()
函数:
alert($(this).siblings('.bidbutton').html());
英文:
Because the jQuery object has no property called innerHTML
. The HTML element does:
alert($(this).siblings('.bidbutton')[0].innerHTML);
Or you can use the .html()
function on the jQuery object:
alert($(this).siblings('.bidbutton').html());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论