4
I need a help with the following problem, I have the following HTML, which is part of an acordion
<div id="accordion2">
<h3 class="btn-sub-main"><a>Banho</a><div class="seta-btn-sub"></div></h3>
<div id="outraDiv">
<ul>
<li><a href="#">condicionadores</a><span></span></li>
<li><a href="#">sabonetes</a><span></span></li>
<li><a href="#">shampoos</a><span></span></li>
<li><a href="#">outros</a><span></span></li>
</ul>
</div>
<h3 class="btn-sub-main"><a>Higiene Infantil</a><div class="seta-btn-sub"></div></h3>
<div id="outraDiv">
<ul>
<li><a href="#">condicionadores</a><span></span></li>
<li><a href="#">sabonetes</a><span></span></li>
</ul>
</div>
<h3 class="btn-sub-main"><a>Alimentação</a><div class="seta-btn-sub"></div></h3>
<div id="outraDiv">
<ul>
<li><a href="#">condicionadores</a><span></span></li>
<li><a href="#">outros</a><span></span></li>
</ul>
</div>
</div>
I have the following Javascript code that changes the background of the DIV="arrow-btn-sub" (arrow image):
$(function() {
$("#accordion2").accordion({
icons: null,
beforeActivate: function( event, ui ) {
$("#" + ui.newHeader.attr("id")).children(".seta-btn-sub").toggleClass("active");
$("#" + ui.oldHeader.attr("id")).children(".seta-btn-sub").toggleClass("active");
},
create: function( event, ui ) {
$("#" + ui.header.attr("id")).children(".seta-btn-sub").toggleClass("active");
}
});
});
I’ve tried in many ways to do what I wish based on this code, but I couldn’t. I want the H3 that has the "btn-sub-main" class to change the background color when the field Aria-Hidden')=='true , or add a class and insert the CSS features I want.
Below is another script that exists in this accordion that hides/shows me to div="otherDiv", I tried to use it by putting the two together in different ways but I couldn’t.
controlaOutraDiv = function(selector){
$("#accordion2 h3", selector).bind('click',function(){
console.log($(this).next().attr('aria-hidden'));
if($(this).next().attr('aria-hidden')=='true'){
$("#outraDiv ul li").show();
}else if($(this).next().attr('aria-hidden')=='false'){
$("#outraDiv ul li").hide();
}
});
}
Code of the accordion effect:
$(function() {
$("#accordion2").accordion({
collapsible: true
});
controlaOutraDiv("#accordion2");
});
Can you add more code here to give a better example of your problem? http://jsfiddle.net/XQdc3/
– Sergio
See if you have improved a little friend, this is all the JS code I have regarding accordion2 and I inserted a little more of html, already showing 2 tables of accordion2.
– CRAJ
Before posting my reply will a tip: on the same page [tag:html] do not put 2 elements with the same
id
as well as see with<div id="outraDiv">
if you need several elements with the same identification use classes like this<div class="outraDiv">
– Erlon Charles