How to get text node after element?

后端 未结 4 999
太阳男子
太阳男子 2020-11-29 09:23

Using jQuery. I have the following html:

 All the world 

How w

4条回答
  •  遥遥无期
    2020-11-29 09:46

    Just to toss in a example to a way old question, wrap text in a label

    $('input[type="checkbox"]')
      .each(function(index, el) {
        var textNode = $(el.nextSibling);
        if (textNode[0].nodeType == Node.TEXT_NODE) {
          let checkwrap = $(el).wrap('').closest('.found');
          textNode.appendTo(checkwrap);
        }
      });
    .found {
      border: solid cyan 1px;
      color: blue;
      padding: 0.5em;
      display: inline-block;
      margin: 0.3em;
    }
    
    label.found {
      color: lime;
    }
    
    in a span
     All the world 
    All the world 2 in a span
    All the world 3 in a span All the world 4in a span also

    there, wrapped in a label, oh wait, that is an answer, just have to get the nextSibling isolated by type

提交回复
热议问题