Need help with javascript to hide button
3 posters
Page 1 of 1
Need help with javascript to hide button
Hello,
I am using the following javascript to hide a button from members:
but it is not working. Can someone help me please?
I am using the following javascript to hide a button from members:
- Code:
jQuery(document).ready(function(){if ((_userdata['user_level'] != '1') || (_userdata["user_level"] != '2')) {
$('#elem1').hide())}};
but it is not working. Can someone help me please?
Re: Need help with javascript to hide button
Hello,
Just a few questions for you:
1)What is your forum Version
2) What is you forum URL
3) Did you check the box for all pages in the JavaScript settings?
4) Did you enable JavaScript code management?
Just a few questions for you:
1)What is your forum Version
2) What is you forum URL
3) Did you check the box for all pages in the JavaScript settings?
4) Did you enable JavaScript code management?
Re: Need help with javascript to hide button
Hello @Sir. MayoSir. Mayo wrote:Hello,
Just a few questions for you:
1)What is your forum Version
2) What is you forum URL
3) Did you check the box for all pages in the JavaScript settings?
4) Did you enable JavaScript code management?
My forum version is PunBB I have set the code in all the pages, I have enabled my javascripts management and my forum url is here.
Best Regards,
Black-Shadow
Re: Need help with javascript to hide button
Thanks.
Nice Forum By the way.
What button where you trying to hide and what users/group where you trying to hide if from?
Nice Forum By the way.
What button where you trying to hide and what users/group where you trying to hide if from?
Re: Need help with javascript to hide button
Hi @Black-Shadow,
The code looked a bit messy on the ending parentheses and brackets. I cleaned it up for you :
If it's still not hidden, check the attributes of the element you're trying to hide to see if you have to correct ID.
You were hiding this for non-staff, correct ? I'll show you a few simplified methods for checking the user state. See the comments for the purpose :
You'll see the first two conditions I used no comparison symbols. It's simple boolean math 0 == false and anything above 0 is true. More simply, the exclamation point (!) inverts our condition performing a check for false values.
The code looked a bit messy on the ending parentheses and brackets. I cleaned it up for you :
- Code:
$(function(){
if (!_userdata.user_level) $('#elem1').hide();
});
If it's still not hidden, check the attributes of the element you're trying to hide to see if you have to correct ID.
You were hiding this for non-staff, correct ? I'll show you a few simplified methods for checking the user state. See the comments for the purpose :
- Code:
if (!_userdata.user_level) console.log('MEMBER'); // if the member is NOT staff e.g. user level == 0
if (_userdata.user_level) console.log('STAFF'); if the member IS staff e.g. user level 1 or 2
// after this you can check the values using comparison symbols.
if (_userdata.user_level == 1) console.log('ADMIN'); // user level 1 == admin
if (_userdata.user_level == 2) console.log('MODERATOR'); // user level 2 == mod
You'll see the first two conditions I used no comparison symbols. It's simple boolean math 0 == false and anything above 0 is true. More simply, the exclamation point (!) inverts our condition performing a check for false values.
![-](https://2img.net/i/empty.gif)
» JavaScript Alert Button Not Working
» How can I add on Toggle Button Javascript slideup/slidedown?
» [HIDE] Button
» Hide Negative Rep Button
» Hide Post Button
» How can I add on Toggle Button Javascript slideup/slidedown?
» [HIDE] Button
» Hide Negative Rep Button
» Hide Post Button
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum