【问题标题】:JQuery- is it possible to grab a nested sibling element after an onclick event?JQuery-是否可以在 onclick 事件后获取嵌套的兄弟元素?
【发布时间】:2021-06-15 20:54:11
【问题描述】:

我正在添加一些功能的旧 Web 表单应用程序遇到问题。

我有一个从数据库动态填充并位于 DataGrid 中的表。我正在尝试添加一个下拉胡萝卜,单击时将显示表格的某个部分。问题是,ID 是由 ASCX 文件动态设置的/或者它不会是唯一的,所以我试图找出一种创造性的方式来抓取它并显示它。

点击上面的P后,是否可以抓取类名为problemDescription的兄弟p?

我尝试过使用这个函数的组合,但它要么什么都不返回,要么返回下一行的 .problemdescription。

function expandDescription(buttonClick) {
        //returns the problem description from the next row
        $(buttonClick).closest('tr').next().find('.problemDescription')
        //does not find anything
        $(buttonClick).closest('td').next().find('.problemDescription')
        //does not find anything
        $(buttonClick).closest('p')
        //does not find anything
        $(buttonClick).next('p')
        //does not find anything
        $(buttonClick).closest('.problemDescription')
    }   

感谢您的帮助!

【问题讨论】:

  • 你想要$(buttonClick).closest('tr').find('.problemDescription')
  • 感谢@charlietfl 就是这样!如果您在下面写下答案,我会为您接受

标签: javascript jquery webforms


【解决方案1】:

$(buttonClick).closest('tr').find('.problemDescription')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    相关资源
    最近更新 更多