javascript - How to check if any span element in inside div has empty value -


i have below code in html file

<div id="tags" style="border:none"> <span class="tag" id="spantag">{{ stu_skill.skill }}</span> </div>   

values inside above span added dynamically server.. there maximum of 7 spans (spans[0],spans[1] , on till spans[6])

how can check if of spans empty in javascript or jquery ?

so far, tried below didn't through

var div = document.getelementbyid("tags"); var spans = div.getelementsbytagname("span"); if (spans[0].innerhtml.length == 0) { spans[0].innerhtml=="empty"; } 

like this, , also

if($('spans[0]').text().length == 0){ $(".tag").text("empty"); window.alert("spans[0] has no value, " + $(".tag").value); } 

i'm trying check if there empty span, if found, need update string "empty" or " "

could please suggest right approach ?

voilĂ , jquery has everything need:

$(".tag:empty").text("empty"); 

http://jsfiddle.net/derekl/qsrrqaq7/


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -