简体   繁体   English

获取具有相同类的当前范围旁边的span元素

[英]Get the span element next to the current span with the same class

I have 我有

    <span class="mention-persons">
     <span class="link-text" id="parent4a275ca0-1bbd-11e4-8b7c-a02bb830bf59">
      <span class="and_text"></span>&nbsp;Elephant Melephant<span onclick="deletemention(this);" id="4a275ca0-1bbd-11e4-8b7c-a02bb830bf59" class="delete-tag">×</span>&nbsp;
     </span>
    <span class="link-text" id="parent5991dff0-1bcf-11e4-908f-a02bb830bf59">
      <span class="and_text">and</span>&nbsp;Dogs Cats<span onclick="deletemention(this);" id="5991dff0-1bcf-11e4-908f-a02bb830bf59" class="delete-tag">×</span>&nbsp;
    </span>
   </span>

Is it possible if i am at at the first link-text or at first and_text or at first delete-tag element i can get the next and-text element using jquery and set it text to empty? 如果我位于第一个link-text ,第一个and_text或第一个delete-tag元素,是否可以使用jquery获取下一个and-text元素并将其文本设置为空?

  1. If you're at the first link-text : 如果您在第一个link-text

    $(this).next('.link-text').children('.and_text').empty();

  2. If you are at the first .link-text or .delete-tag use: 如果您是第一个.delete-tag .link-text.delete-tag使用:

    $(this).closest('.link-text').next('.link-text').children('.and_text').empty();

  3. UPDATE UPDATE

Irrespective of where you are on the first .link-text , you can use the following: 无论您在第一个.link-text上的位置如何,都可以使用以下命令:

  var that = $(this).is('.link-text') ? $('.link-text') : $(this).closest('.link-text');
  that.next('.link-text').children('.and_text').empty();

您可以尝试如下操作:

$(this).parents(".link-test").next(".link-text").children(".and_text").text('');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM