jeudi 26 mars 2015

Jquery if div hasClass do something with a other div

Here is my problem (besides the fact that i'm a beginnen with javascript). I am building a page that wil load ajax content into a HTML page with a tab plugin. We need to build one page only which has to carry loads of content. Everything is working fine but we need to have little enhancement that uses javascript.


The first set are the tabs (ul.tabs) the second set are the content placeholders (div.panel-container) the third set is a layer popup (div#popup)



<div id="ajax-tab-container" class='tab-container'>

<ul class='tabs'>
<li class='tab'><a href="file.html #section-one" data-target="#one" class="index">one</a></li>
<li class='tab'><a href="file.html #section-two" data-target="#two" class="blue">two</a></li>
<li class='tab'><a href="file.html #section-three" data-target="#three" class="green">three</a></li>
</ul>

<div class='panel-container'>
<div id="one" class="active"></div>
<div id="two"></div>
<div id="three"></div>
</div>

<div id="#popup">
<div class="one-ph">Content</div>
<div class="two-ph">Content</div>
<div class="three-ph">Content</div>
</div>


Now based on which tab is active the current scripts set the active status. Now what i need to do is create a script that checks (hasClass) which div within the .panel-container hasClass "active". But then it should addClass to the div within div#popup. But they have to match.


So if div#one hasClass "active" then addClass to div.one-ph, if div#two hasClass "active" then addClass to div.two-ph etc.


Now in this example there are only three but the finished document will have about 20. kan somebody help me create this, i tried almost every example but is does not work. Also this is not a click function but a function that should work probably on document ready.


Please help this desperate guy


Aucun commentaire:

Enregistrer un commentaire