jQuery选择器问题

时间:2009-06-08 08:56:47

标签: jquery html css-selectors

这是我的html源代码:

<ul id="accordion">
 <li><h3><a id="1"></a></h3></li>
 <li><h3><a id="2"></a></h3></li>
 <li><h3><a id="3"></a></h3></li>
</ul>

和javascript

<script type="text/javascript">
 $(document).ready(function(){
  $('#accordion li h3').click(function(){
   //I want to alert the id attribute of a, but i don't know why
   //I tried $(this+'a') or $('#accordion li h3:selected a') but it failed.
  });
 });
</script>

1 个答案:

答案 0 :(得分:2)

尝试

alert($(this).children('a').attr('id'))