javascript - How do I select an element that matches a .text() == "" condition? -
this want do:
<label class="myclass"></label> <!-- want hide --> <label class="myclass">some text here</label> <!-- don't hide --> $('label.myclass').text() == "" ) { $('this').hide(); }
of course, $(this)
points window, not label.myclass
meets condition. how rewrite i'm selecting labels nt have text inside it?
var label = $('label.myclass').filter(function (index) { if ($(this).text() == "") { return $(this) } }) console.log(label.attr('class')) console.log(label.text()) console.log(label.length)
use .filter()
Comments
Post a Comment