Simple jQuery Show / Hide
I have an input which is hidden which carrys a value based on that value I w开发者_如何学Could like to show a menu item.
i.e. if value in field = 1 than show menu item 1 else if value in field is not 1 then hide menu item 1
my jquery
$(function() {
$("#sessionVal".val(==1){
$("#adminMenu").show();
});
$("#sessionVal".val(!=1){
$("#adminMenu").hide();
});
});
Really simple I am sure for most can anyone help?
$(document).ready(function() {
if( $("#sessionVal").val() == 1) {
$("#adminMenu").show();
} else {
$("#adminMenu").hide();
};
});
Not sure when do you want it to run, in this example it will check the field once page is loaded, you can bind however click, focus or other events when it should be done..
if($('#sessionVal').val() == 1) {
$('#adminMenu').show();
} else {
$('#adminMenu').hide();
}
Should do the trick.
Note I am using == instead of === because I'm assuming the value attribute won't necessarily get returned as number
You got your syntax wrong
if ( $("#sessionVal").val() == 1 )
Justin, instead of .val(==1)
, try .val()=='1'
, and the same for the other statement. I believe that would throw you an error, am I right?
Hope to have helped.
精彩评论