gilgimech
01-15-2011, 03:26 PM
I jusy found this wierd bug with toggleClass().
here's the code I'm working with
html
<div id="contentContainer" class="contentContainer">
<div id="contentContainerHeader" class="containerHeader001"></div>
</div>
css
#contentContainer{
width:190px;
min-height:200px;
margin-top:10px;
}
#contentContainerHeader{
width:190px;
height:30px;
background-repeat:no-repeat;
}
.contentContainerHeader001{
width:190px;
height:30px;
background-image:url(../images/header-001.png);
background-repeat:no-repeat;
}
.containerContainerHeader002{
width:190px;
height:30px;
background-image:url(../images/header-002.png);
background-repeat:no-repeat;
}
jQuery
$(document).ready(function() {
$('.contentContainer').hover(over, out);
function over(event) {
$(this).children('.contentContainerHeader001').toggleClass('contentContainerHeader002');
}
function out(event) {
$(this).children('.contentContainerHeader002').toggleClass('contentContainerHeader002');
}
});
Now, it seems that the position of the "contentContainerHeader001" and "contentContainerHeader002" matter on the css file.
Everything works the way it is, but if I switch the css araound like this. With "contentContainerHeader002" before "contentContainerHeader001"...
.containerContainerHeader002{
width:190px;
height:30px;
background-image:url(../images/header-002.png);
background-repeat:no-repeat;
}
.contentContainerHeader001{
width:190px;
height:30px;
background-image:url(../images/header-001.png);
background-repeat:no-repeat;
}
It no longer works.
I couldn't find any documentation about the css position mattering.
Could someone explain why this is happening?
here's the code I'm working with
html
<div id="contentContainer" class="contentContainer">
<div id="contentContainerHeader" class="containerHeader001"></div>
</div>
css
#contentContainer{
width:190px;
min-height:200px;
margin-top:10px;
}
#contentContainerHeader{
width:190px;
height:30px;
background-repeat:no-repeat;
}
.contentContainerHeader001{
width:190px;
height:30px;
background-image:url(../images/header-001.png);
background-repeat:no-repeat;
}
.containerContainerHeader002{
width:190px;
height:30px;
background-image:url(../images/header-002.png);
background-repeat:no-repeat;
}
jQuery
$(document).ready(function() {
$('.contentContainer').hover(over, out);
function over(event) {
$(this).children('.contentContainerHeader001').toggleClass('contentContainerHeader002');
}
function out(event) {
$(this).children('.contentContainerHeader002').toggleClass('contentContainerHeader002');
}
});
Now, it seems that the position of the "contentContainerHeader001" and "contentContainerHeader002" matter on the css file.
Everything works the way it is, but if I switch the css araound like this. With "contentContainerHeader002" before "contentContainerHeader001"...
.containerContainerHeader002{
width:190px;
height:30px;
background-image:url(../images/header-002.png);
background-repeat:no-repeat;
}
.contentContainerHeader001{
width:190px;
height:30px;
background-image:url(../images/header-001.png);
background-repeat:no-repeat;
}
It no longer works.
I couldn't find any documentation about the css position mattering.
Could someone explain why this is happening?