Show Hide Button in PHP using Javascript dont want Jquery

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

stephenrodrics
New php-forum User
New php-forum User
Posts: 60
Joined: Thu Mar 14, 2013 6:10 am

Show Hide Button in PHP using Javascript dont want Jquery

Postby stephenrodrics » Sun Mar 31, 2013 11:59 pm

Hi,

I want to write some basic script without using Jquery to show hide some buttons, is there any way we can do in Javascript or HTML or PHP.

Thanks

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Show Hide Button in PHP using Javascript dont want Jquer

Postby seandisanti » Mon Apr 01, 2013 9:17 am

Can I ask why you don't want to use jquery? Just seems kind of arbitrary if a javascript solution is ok.

stephenrodrics
New php-forum User
New php-forum User
Posts: 60
Joined: Thu Mar 14, 2013 6:10 am

Re: Show Hide Button in PHP using Javascript dont want Jquer

Postby stephenrodrics » Mon Apr 01, 2013 11:58 pm

thanks for the reply, now I have done it with javascripots as it seems much more clean and easy compared to Jquery

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Show Hide Button in PHP using Javascript dont want Jquer

Postby seandisanti » Tue Apr 02, 2013 7:13 am

jquery is javascript, and all it does is give you the ability to use css style selectors and a uniform library that works the same regardless of the browser. As long as you got the result you want, that's what's important, but you may really want to look at http://www.w3schools.com/jquery/default.asp to see how easy and clean jquery can be.

User avatar
Strider64
New php-forum User
New php-forum User
Posts: 84
Joined: Sat Mar 23, 2013 8:24 am

Re: Show Hide Button in PHP using Javascript dont want Jquer

Postby Strider64 » Tue Apr 02, 2013 12:34 pm

JQuery is just a JavaScript Library that makes coding simpler, for programmers are lazy in general. :D

Even w3schools uses JQuery in their JavaScript examples and I despise that site.
Here's an example on how to do it using a key press using the ~ Key to unhide the the button. You could get fancier in incorporating a toggle switch, but I just use this feature to hide a login button from a page. The login button looks ugly in my opinion and the hide feature doesn't serve as a security feature for all one has to do is look at the html source code. :D

Code: Select all

<head>
.......
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
   $(document).keypress(function(e) {
     if(e.which == 126) {
        $('#hide-btn').removeClass('hide-btn');
     }
   });
</script>
......
</head>

<body>
<div id="hide-btn" class="hide-btn">
      ..........html code......
</div>


However, there are a lot of examples on the web how to do it purely in JavaScript, but I would rather write in with fewer lines myself. ;)


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests