从单击的元素中检索文本

时间:2012-10-21 14:05:37

标签: jquery html onclick

<div class="forInfo">
<div style="text-align:center; font-weight:bold;">17:00:00</div><br>
<div style="text-align:center; font-weight:bold; font-size:large">zumba</div>
<div style="display:none" class="opis"> Ime instruktorja: ime Opis:opis</div>
<div style="text-align:center">ime</div>
</div>

这是html代码。我使用带有“opis”类的div只是为了存储文本。

 $(".forInfo").click(function(){alert($(".opis",this).text)});

我已经在jquery中编写了这个函数,所以每当我点击带有“forInfo”类的div时,我会得到一个带有“opis”类的元素中文本的警报。但是这不起作用,我得到了用我的aler编写的文本函数。

1 个答案:

答案 0 :(得分:4)

text是一种方法,而不是属性。请参阅docs here

 $(".forInfo").click(function(){alert($(".opis",this).text())});

Working example.

相关问题