Improve js written for guides

* Stop using unnecessary global variable
* Use function defined by jQuery for simplicity