Jquery 如何在下一页中追加数据<;李>;

Jquery 如何在下一页中追加数据<;李>;,jquery,html,Jquery,Html,我想在单击时将数据附加到最近的li上…我尝试了下一步,父级,最近,查找,什么都没有 这是我的JSFIDLE 我的jquery: $(document).ready(function(){ $(document).on('click', '.btnMoreInfo', function(){ $(this).closest(".test").next('.infoCatcher').append('<div class="moreInfo info">More C

我想在单击时将数据附加到最近的li上…我尝试了下一步,父级,最近,查找,什么都没有

这是我的JSFIDLE

我的jquery:

$(document).ready(function(){
   $(document).on('click', '.btnMoreInfo', function(){
       $(this).closest(".test").next('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
   });
});
$(文档).ready(函数(){
$(文档).on('单击','.btnMoreInfo',函数(){
$(this).test(“.test”).next('.infoCatcher').append('More Content..'+'');
});
});

它不起作用。我可以知道为什么以及如何修复它吗?谢谢

另一种方法是使用
儿童
最近的
方法

$(document).ready(function(){
    $(document).on('click', '.btnMoreInfo', function(){
      $(this).closest("li").next().children('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
    });
});
$(文档).ready(函数(){
$(文档).on('单击','.btnMoreInfo',函数(){
$(this).closest(“li”).next().children('.infoCatcher').append('More Content..'+');
});
});

另一种方法是使用
子类
最接近的
方法

$(document).ready(function(){
    $(document).on('click', '.btnMoreInfo', function(){
      $(this).closest("li").next().children('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
    });
});
$(文档).ready(函数(){
$(文档).on('单击','.btnMoreInfo',函数(){
$(this).closest(“li”).next().children('.infoCatcher').append('More Content..'+');
});
});
使用
closest()
只遍历三个DOM,因为
.test
是您按钮的父级的兄弟,您没有找到任何内容

你需要像这样的东西:

$(this).parent().next().find('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
$(this.parent().next().find('.infoCatcher').append('More Content..'+');
这将是:

  • $(此)
    实际按钮
  • .parent()
    到li父级
  • .next()
    将标记上的下一个li作为.test的目标
  • .find('.infoCatcher')
    并在div infoCatcher上追加
使用
closest()
只遍历三个DOM,因为
.test
是您按钮的父级的兄弟,您没有找到任何内容

你需要像这样的东西:

$(this).parent().next().find('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
$(this.parent().next().find('.infoCatcher').append('More Content..'+');
这将是:

  • $(此)
    实际按钮
  • .parent()
    到li父级
  • .next()
    将标记上的下一个li作为.test的目标
  • .find('.infoCatcher')
    并在div infoCatcher上追加

下面是一个纯Javascript示例,说明如何针对最近的
li

还有这个片段:

var closestLi=document.body.firstElementChild.firstElementChild;
var content=document.createTextNode(“此处的内容”);
closestLi.appendChild(内容)
  • 更多
  • 更多
  • 更多
  • 更多

下面是一个纯Javascript示例,说明如何瞄准最接近的
li

还有这个片段:

var closestLi=document.body.firstElementChild.firstElementChild;
var content=document.createTextNode(“此处的内容”);
closestLi.appendChild(内容)
  • 更多
  • 更多
  • 更多
  • 更多

最近的li将是按钮的父级。。。你是说最接近的李级考试吗?我不知道你想在这里取得什么成绩。你只是想得到更多的信息,就像小提琴?谢谢@DaniP!。。。把这当作一个有效的答案!最近的li将是按钮的父级。。。你是说最接近的李级考试吗?我不知道你想在这里取得什么成绩。你只是想得到更多的信息,就像小提琴?谢谢@DaniP!。。。把这当作一个有效的答案!