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()

demo


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -