获取触发Jquery函数的元素的ID

时间:2010-12-09 09:35:20

标签: jquery

我有一个转发器,每行都会显示一个工具提示,每个工具提示都会包含行ID,这是我的代码:

$(document).ready(function () { 
        $('tr.SomeClass').qtip({
            content: {
                        text:  // here I want to get the id of the row
            },

1 个答案:

答案 0 :(得分:3)

你需要使用.each()来遍历这里的元素,如下所示:

$(document).ready(function () { 
  $('tr.SomeClass').each(function() {
    $(this).qtip({
        content: {
          text:  "My ID is: " + this.id
        }
    });
  });
});

使用这种方法,this引用每个tr.SomeClass元素,而不是您所处的任何上下文(之前document),因为您在{{1}处理程序)。

相关问题