如何在jQuery中获取内部div的id值?

时间:2015-08-23 04:48:05

标签: javascript jquery html

在我的页面上div结构如下:

<div class="row no-padding">
  <div class="col-sm-3 col-lg-5 widget-left">
    <em class="glyphicon glyphicon-user glyphicon-l"></em>
  </div>
  <div class="col-sm-9 col-lg-7 widget-right">
    <?php echo '<div id="shop1" class="large">'. $row["0"]. '</div>';?>
    <div class="text-muted">User Details</div>
  </div> <!-- $row['id'] also in query for uniqueness -->
</div>

看起来像这样:

enter image description here

点击课程row no-padding时,我想将文字提醒为“Hadapsar”,“Kolhapur”等。目前我的jQuery代码仅适用于课程large

$(document).ready(function(){
  $('.large').click(function(event) {
    var ar = $(this).text();
    alert(ar);
    pune_shop(ar);
  });
});

1 个答案:

答案 0 :(得分:2)

请尝试

$(document).ready(function(){
    $('.row.no-padding').click(function(event) {
        var ar = $(this).find('.large').text();
        alert(ar);
        pune_shop(ar);
    });
});