Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jQuery change style of parent items if text value exists?

Posted on 2012-12-31
2
Medium Priority
?
460 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
2 Comments
 
LVL 11

Accepted Solution

by:
Ovid Burke earned 2000 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

Industry Leaders: 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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

916 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