html - how to select special tag after another special tag with jquery -


i have html page <input> tag came after <span class="class1"> want select input tags disabled

how can jquery selector?

i'm test $('span.class1+ :disabled') , not work !

my html somthing this:

<span class="class1"></span> <input type="text" disabled/> <span class="class1"></span> <input type="text"/> <input type="text" disabled/> 

i want select input first input (note: not third input)

the other answers have no limit on when stop searching. process all siblings after each class1 span (regardless of span between them, should act "fences").

based on layout, want stop after hits next span, use nextuntil limit search , filter target required elements:

$(document).ready(function(){    $('span.class1').nextuntil('span').filter('input:disabled').val('disabled text box')  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <span class="class1"> span class1 </span>  <input type="text" class="" disabled /><br/>  <span class="class1"> span class1 </span>  <input type="text" disabled/><br/>  <span class="class1"> span class1 </span>  <input type="text"/><br/>  <input type="text" disabled/><br/>  <span class="class2"> span class2 </span>  <input type="text"/><br/>  <input type="text" disabled/>

you note 1 not set text of last input (as not following class1 span.

as @nishit maheta noted (after appending answer his) can shorten to:

$('span.class1').nextuntil('span', 'input:disabled').val('disabled text box') 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -