how to hide a div that is empty and another div associated with it which may or maynot be empty?

I have a speech bubble called philosophy bubble which is just a div styled to look like a quote bubble and the sharepoint control is what fills up the content of the bubble but sometimes the bubble may not have any text and needs to be hidden. Not just the bubble but also the text below which is like 'Mr. X's saying' should be hidden since the bubble is empty. How is is achieved in jquery?

<div class="philosophy-bubble">Quote goes here                  
</div>                              
<span class="credit">
Quoter..
</span>

Answers


Assuming you only want to hide the bubbles that have no text in them, you could do it this way:

$(".philosophy-bubble").each(function() {
    if (this.innerHTML.match(/\S/)) {
        $(this).hide().next(".credit").hide();

    }
});

If you have access to the HTML, you could wrap both the <div> and <span> in a parent <div> tag. The parent could then be hidden.

$('.philsophy-bubble').parent().hide()

If you have access to jQuery (I see you tagged this jQuery), you can use the .next() function which gets the next sibling (vertically).

Something like...

$('.philosophy-bubble').hide().next().hide();


Need Your Help

Can nflx:// app run within an IOS app using UIWebView

iphone

I am writing an IOS app where I would like to launch the Netflix app (nflx://) within my app using UIWebView. I would like to have the Netfix movies run within my UIWebview structure so when the...

XMS allocation in 16-bit DOS

c dos 16-bit watcom

Please forgive my attempts at necromancy, but I actually need to write some code for 16-bit DOS (!). I have to verify that a piece of software executes correctly when built for a 16-bit platform, a...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.