IshaS
IshaS

Reputation: 837

find text is there inside a div with jQuery?

I have a div like this

<div id="test"></div>

I want to find if there are any text inside the div. how can I find it with jQuery?

Upvotes: 1

Views: 49

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67187

You can use :empty selector along with .is() function to achieve what you want.

Try,

if($('#test').is(':empty')){
  //Its empty go ahead
}

Or

if($.trim($("#test").text()) === ""){
  //Its empty go ahead
}

Upvotes: 3

Related Questions