Title: Javascript in WordPress pages
Last modified: August 21, 2016

---

# Javascript in WordPress pages

 *  [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/)
 * Hello,
 * I’ve been trying everything in order to add a simple onclick event here and there
   in some pages and posts. What I need to add is this:
 * `<a style="cursor:pointer;" onclick="javascript: alert('Various text according
   to situation');">*</a>`
 * If you check the home page or the posts in my website, you will see asterisks
   with disclaimers which need to be there by law. Of course everytime I edit the
   page, the code gets stripped. What can I use instead of that?
 * Thanks
 * [http://www.phylnex.com/](http://www.phylnex.com/)

Viewing 9 replies - 16 through 24 (of 24 total)

[←](https://wordpress.org/support/topic/javascript-in-wordpress-pages/?output_format=md)
[1](https://wordpress.org/support/topic/javascript-in-wordpress-pages/?output_format=md)
2

 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830211)
 * Also, for different statements I need to use different disclaimers but still 
   using an asterisk. That’s why I was using that line of code which, let’s be honest,
   should work.
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830212)
 * Aaaahhhh…. thanks for explaining… 🙂 Let me try
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830213)
 * Okay now, :)… sorry to bug you again.
 * If you try here [http://www.phylnex.com/let-me-tell-you-my-story/](http://www.phylnex.com/let-me-tell-you-my-story/)
   
   You will see toward the bottom of the post that I have inserted the asterisks…
   Click on one, the popup opens, brilliant…but when you close it, it move the page
   to the top which can be quite annoying. Can I use the nohref attribute instead
   of href=”#”?
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830214)
 * Also the first two asterisks work, then the rest don’t. Question. Are the following
   okay?
 *     ```
       jQuery(document).ready(function($) {
   
        $('#testimonial').click(function() {
         alert('Any testimonial is unique to the individual and actual results may vary.');
        });
   
       });
   
       jQuery(document).ready(function($) {
   
        $('#disclaimer').click(function() {
         alert('These statements have not been evaluated by the Food and Drug Administration. This product is not intended to diagnose, treat, cure, or prevent any disease. This article is for informational purposes only. See a professional health care provider if you are in need of medical care. This article is not a substitute for medical care. ');
        });
   
       });
       ```
   
 * And then wherever I need, in **multiple occasions**, I use :
 * `<a style="cursor:pointer;" nohref id="disclaimer">*</a>`
    or `<a style="cursor:
   pointer;" nohref id="testimonial">*</a>` ?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830215)
 * > Click on one, the popup opens, brilliant…but when you close it, it move the
   > page to the top which can be quite annoying
 * You could do things like disable the behaviour with the href, like so (preventDefault):
 *     ```
       jQuery(document).ready(function($) {
   
        $('#that-link').click(function(event) {
         event.preventDefault();
         alert('Various text according to situation');
        });
   
       });
       ```
   
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830216)
 * The disclaimer seems to work for me
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830227)
 * Yes the first two work. But try the asterisk where it says
 * > and the pain would vanish along with the stones. It was amazing how quickly
   > the pain went away and how quickly, easily and pain-free the stones were passing.*
 * It doesn’t do anything
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830231)
 * How about (maybe that would be easier) If I add a Javascript code (whatever that
   would be) in the website’s footer to hook to a certain class to add a hover effect
   so that when people hover over a certain paragraph, a little text box with the
   disclaimer appears?
 * Any suggestion?
 *  [maya923](https://wordpress.org/support/users/maya923/)
 * (@maya923)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830249)
 * TabyP, you should just try the HTML Snippets plug-in.
    I’m really ticked I had
   to resort to it, but my PayPal buttons are now back where they belong. It allows
   you to insert shortcode in place of what you need.
 * I actually linked it in this post, but like everything else WP-related, it doesn’t
   work.
 * `<a href="http://wordpress.org/plugins/insert-html-snippet//"></a>`

Viewing 9 replies - 16 through 24 (of 24 total)

[←](https://wordpress.org/support/topic/javascript-in-wordpress-pages/?output_format=md)
[1](https://wordpress.org/support/topic/javascript-in-wordpress-pages/?output_format=md)
2

The topic ‘Javascript in WordPress pages’ is closed to new replies.

## Tags

 * [alert](https://wordpress.org/support/topic-tag/alert/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [onclick](https://wordpress.org/support/topic-tag/onclick/)
 * [script](https://wordpress.org/support/topic-tag/script/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 24 replies
 * 4 participants
 * Last reply from: [maya923](https://wordpress.org/support/users/maya923/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/page/2/#post-4830249)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
