Solved

jQuery change style of parent items if text value exists?

Posted on 2012-12-31
2
431 Views
Last Modified: 2013-02-25
Hi Another quick jquery question. Should be a nice easy one for some of you.
I am trying to show a hidden div and it's contents if a hidden span has any text in it.
The text only appears if a placeholder has a value but remains hidden always.
If the div and contents is shown at the same time I want the content of another div to become hidden.
I've tried the below which doesn't trigger anything.

jquery
 $(document).ready(function(){
//  Hides image and shows video if text has a value
  		var BlogVid = $(".inner-banner div.youtube span.hide").text(); 
		if ($(BlogVid).val() != '') { 
		$(this).parents(".inner-banner div.youtube").css('display', 'block');
		$(this).parents(".inner-banner div.absolute img").css('display', 'none');
}   
});

Open in new window


html
<section class="frame inner-banner"> <img alt="" src="/ImgLayout/frame.png" />
    <div class="absolute"><img src="{tag_MainImage585x327_value}" alt="{tag_name}" title="{tag_name}" /> </div>
    <div class="absolute youtube video" style="display: none;"><iframe width="602" height="336" src="http://www.youtube.com/embed/{tag_YouTubeID}?rel=0" frameborder="0"></iframe>
    <span class="hide" style="display: none;">{tag_YouTubeID}</span></div>
    </section>

Open in new window


I would appreciate help,
regards
Lee
0
Comment
Question by:boxhedge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Ovid Burke earned 500 total points
ID: 38732349
Revised jQuery:

$(document).ready(function() {
    var videoID = $('span.hide');
    
    if( videoID.text() != '' ) {
        videoID.parent('.video').css({display: 'block'}).siblings('.absolute').css({display: 'none'})
    }
});

Open in new window


Fiddle: http://jsfiddle.net/Zg9rF/
0
 

Author Closing Comment

by:boxhedge
ID: 38732569
Perfect thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question