The problem with this implementation is that it consider tablet also as a mobile device. So the design might need to suffer a bit.
You should realize that this does not detect a mobile phone specifically, as a tablet is considered a mobile device
-from documentation.
The best way to implement this is to use Media Queries. Check the below link for a sample script.
http://stackoverflow.com/questions/21649274/how-to-show-hidden-button-with-css-media-query