Find first empty class div

  • A+
Category:Languages
<input type='text' class='inptag' id='inptag'>  <div class='tagstore' id='tagstore'>     <div class='tagsingle'></div>     <div class='tagsingle'></div>     <div class='tagsingle'></div>     <div class='tagsingle'></div>     <div class='tagsingle'></div> </div> 

js

I need to find first empty tagsingle and make its text as a.

$('#inptag').keypress(function(e) {     if (event.keyCode === 13) {         e.preventDefault();         var a = $(this).val().trim();         // here I need something like:         $('.tagsingle:first-empty').text(a);     } }); 

Any help?


Use first and empty separately as

$('.tagsingle:empty:first').text(a); //get empty first and then first 

Demo

$('#inptag').keypress(function(e) {   if (event.keyCode === 13) {     e.preventDefault();     var a = $(this).val().trim();     // here I need something like:     $('.tagsingle:empty:first').text(a);   } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type='text' class='inptag' id='inptag'>  <div class='tagstore' id='tagstore'>   <div class='tagsingle'></div>   <div class='tagsingle'></div>   <div class='tagsingle'></div>   <div class='tagsingle'></div>   <div class='tagsingle'></div> </div> js

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: