Solved

jQuery change style of parent items if text value exists?

Posted on 2012-12-31
2
445 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

635 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