jQuery - Can the show() function return true?
I have make a script by using jQuery such as :
$(document).ready(function() {
$('a[name=pmRead]').click(function(e) {
e.preventDefault();
var pmtext=$(this).parents(".pmMain").find(".pmMain5");
});
});
Now, I'd like to use a function 开发者_Python百科like pmtext.show() and get TRUE if the element is visible. Else, I'd like to return FALSE. Any change to get TRUE/FALSE by using show()? (or the sister function hide()).
There is a function to check the visibility, but it is not show()/hide()
.
if (pmtext.is(':visible')) {
// ....
}
Why not use the following:
pmtext.is(":visible");
That will provide a boolean true if it is visible and false if it is not. For the converse you can use pmtext.is(":hidden");
.
If you want to do something on visible, try:
$(this).parents(".pmMain").find(".pmMain5:visible").hide(); // only finds it if visible
I'd suggest writing a custom function if you need to return true or false.
function customShow(element)
{
if( $( element ).is( ':visible' ) )
return true;
$( element ).show();
return false;
}
You can write your own simple function, to check if its visible or not.
Note: The function takes a jQuery element as input.
function isVisible($element) {
return $element.css("display").toLowerCase() != "none");
}
Have you looked at the .toggle() method? It optionally accepts a "showOrHide" argument.
<script language="JavaScript">
function menu(bolum) {
if ( bolum.style.display =='none')
{ bolum.style.display='';islem.style.display='';} else {bolum.style.display='none';}
}
</script>
<img src="images/biz-arayalim.png" onclick="menu(firmamesajkutusu)" style="cursor:pointer;">
<div name="firmamesajkutusu" id="firmamesajkutusu"></div>
Old system javascript all div kontrol function
精彩评论