this.sibling is undefined why is it happening

huangapple go评论118阅读模式
英文:

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);
});

https://jsfiddle.net/vhteLgmr/

答案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());

huangapple
  • 本文由 发表于 2023年4月6日 19:56:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949244.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定