admin管理员组文章数量:1417555
$("#id_btnquizzestwo").click(function() {
$temp = $("#rightsideeightone").is(":visible");
if($temp) {
$("#rightsideeightone").css('display') = 'none';
}
})
The rightsideeightone division is not being hidden.
What to do ?
$("#id_btnquizzestwo").click(function() {
$temp = $("#rightsideeightone").is(":visible");
//alert($temp);
if($temp) {
$("#rightsideeightone").hide();
}
$temp2 = $("#rightsideeighttwo").is(":hidden");
//alert($temp2);
if($temp2) {
$("#rightsideeighttwo").show();
}
})
I tried this, the rightsideeighttwo is not being visible. Initialy the rightsideeightone is visible and the rightsideeighttwo is hidden.
<div id="rightsideeight" >
<div id="id_pollsquizzes" >
<?php echo '<ul>'; ?>
<?php
echo '<li>';
echo $this->Form->button('Polls',array('type'=>'button','id'=>'id_btnpollstwo'));
echo '</li>';
echo '  ';
echo '<li>';
echo $this->Form->button('Quizzes',array('type'=>'button','id'=>'id_btnquizzestwo'));
echo '</li>';
echo '  ';
?>
</div>
<div id="rightsideeightone" style="visibility: visible" >
......................
</div>
<div id="rightsideeighttwo" style="visibility: hidden" >
......................
</div>
</div>
$("#id_btnquizzestwo").click(function() {
$temp = $("#rightsideeightone").is(":visible");
if($temp) {
$("#rightsideeightone").css('display') = 'none';
}
})
The rightsideeightone division is not being hidden.
What to do ?
$("#id_btnquizzestwo").click(function() {
$temp = $("#rightsideeightone").is(":visible");
//alert($temp);
if($temp) {
$("#rightsideeightone").hide();
}
$temp2 = $("#rightsideeighttwo").is(":hidden");
//alert($temp2);
if($temp2) {
$("#rightsideeighttwo").show();
}
})
I tried this, the rightsideeighttwo is not being visible. Initialy the rightsideeightone is visible and the rightsideeighttwo is hidden.
<div id="rightsideeight" >
<div id="id_pollsquizzes" >
<?php echo '<ul>'; ?>
<?php
echo '<li>';
echo $this->Form->button('Polls',array('type'=>'button','id'=>'id_btnpollstwo'));
echo '</li>';
echo '  ';
echo '<li>';
echo $this->Form->button('Quizzes',array('type'=>'button','id'=>'id_btnquizzestwo'));
echo '</li>';
echo '  ';
?>
</div>
<div id="rightsideeightone" style="visibility: visible" >
......................
</div>
<div id="rightsideeighttwo" style="visibility: hidden" >
......................
</div>
</div>
Share
Improve this question
edited Sep 7, 2011 at 7:56
cola
asked Sep 7, 2011 at 6:50
colacola
12.5k36 gold badges108 silver badges166 bronze badges
3
- I have edited the original post/question and the html code to understand. – cola Commented Sep 7, 2011 at 7:57
- What html is generated by this string? echo $this->Form->button('Polls',array('type'=>'button','id'=>'id_btnpollstwo')); And besides you haven't closed ul element. – Arsen Kazydub Commented Sep 7, 2011 at 8:12
- @Webars, is this what you are looking for ? jsfiddle/LQg7W/85 – cola Commented Sep 7, 2011 at 8:24
4 Answers
Reset to default 6The line
$("#rightsideeightone").css('display') = 'none';
is incorrect. To change a style property, use this syntax:
$("#rightsideeightone").css('display','none');
Checking the visibility isn't necessary - if the element $("#rightsideeightone") is already hidden then hiding it again has no effect, so your function can be written as:
$("#id_btnquizzestwo").click(function() {
$("#rightsideeightone").css('display','none');
});
Assuming that the $temp
variable equals false you could try:
$('#rightsideeightone').hide();
All three explanation should work. But just for clarification:
Using this:
$("#rightsideeightone").css('display') = 'none';
Isn't working due to .css('display')
this is a getter. As in get the current value of the display
property. So what you are basically doing here is first getting the value (say 'block') and then try to assign a new value ('none') to it. It would be the equivalent of: (just for explanation, doesn't actually work):
'block' = 'none';
You need to set the value of display on the element not just overwrite the propert you get. Hence use the jQuery setter:
$("#rightsideeightone").css('display','none');
// OR
$("#rightsideeightone").css({ display: 'none' });
I prefer the later one.
Hope I explained it more the confused it :)
http://jsfiddle/LQg7W/89/
.visible { display: block; }
.hidden { display: none; }
$("#id_btnquizzestwo").click(function() {
if( $("#rightsideeightone").is(".visible") )
$("#rightsideeightone").removeClass("visible").addClass('hidden');
if( $("#rightsideeighttwo").is(".hidden") )
$("#rightsideeighttwo").removeClass("hidden").addClass('visible');
});
本文标签: javascriptjQuery division visibility hidden is not workingStack Overflow
版权声明:本文标题:javascript - jQuery division visibility hidden is not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745268135a2650728.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论