alf_red
alf_red

Reputation: 122

Div is empty. With jQuery...false?

I have this div (<div id="slideshow">). In index.php is full. In the other pages is empty. (I use Joomla, and that is a module). Now, when is full, it's ok. But, when it's empty, I want change a css property of next div. (<div id="slideshow">...</div><section>....</section>). Now, I try this code :

            alert($("div#slideshow").text() == "");
            alert($("div#slideshow").is(':empty'));

The result in all pages are: False , False. False??? for all? p.s. for empty I want to say this (<div id="slideshow"></div>). Thanks for the answer.


I understood where wrong. With chrome I saw (<div id="slideshow"></div>), but copying it as html gave me this:

<div id="slideshow">

             </div>

So it's not empty! Now I wonder, how do I proceed?

Upvotes: 0

Views: 471

Answers (3)

Niko
Niko

Reputation: 26730

How about trimming the whitespaces before comparing with an empty string?

$.trim( $('#slideshow').text() ) == ''

Upvotes: 0

nickf
nickf

Reputation: 546253

The text of this element is != "" but it is empty:

<div> </div>

Upvotes: 1

benedict_w
benedict_w

Reputation: 3608

Try $("div#slideshow").html()

"In an HTML document, .html() can be used to get the contents of any element" - http://api.jquery.com/html/

"The result of the .text() method is a string containing the combined text of all matched elements" - http://api.jquery.com/text/

Upvotes: 0

Related Questions