Solved

jQuery change style of parent items if text value exists?

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now