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 15 replies - 1 through 15 (of 24 total)

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

 *  [maya923](https://wordpress.org/support/users/maya923/)
 * (@maya923)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/#post-4830112)
 * Ironically, I came here for the exact same question, except it’s to make PayPal
   buttons.
 * My code is as follows:
 * `<input onclick="x=window.open('https://www.paypal.com/cgi-bin/webscr?cmd=_s-
   xclick&hosted_button_id=XXX')" type="button" value="Add to Cart" />`
 * It always worked until I upgraded to 3.9.
 * Help?
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/#post-4830156)
 * Yeah that’s what happened to me. It worked before without any problem. Then I
   updated to 3.9…
 * I hope someone replies soon
 *  [meraj.khattak](https://wordpress.org/support/users/merajkhattak/)
 * (@merajkhattak)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/#post-4830157)
 * Does this problem get solved? I am able to click on the * and it opens an alert
   window showing the disclaimer message.
 * I am using Chrome latest version.
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/#post-4830186)
 * Some pages still work because I haven’t edited them since the wordpress update.
   Check here [http://www.phylnex.com/let-me-tell-you-my-story/](http://www.phylnex.com/let-me-tell-you-my-story/)
   
   You can see the asterisk and if you check the element with dev tools, the onclick
   is stripped. That is because I have edited the page AFTER the WordPress update.
   I’m still waiting for someone to post a solution.
 *  [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/#post-4830190)
 * Why are you using inline JS, TabyP? I’m genuinely interested.
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/#post-4830194)
 * I’m not sure I know any other method to be honest? I need different types of 
   popups in different locations of a page. I thought that would be the easiest 
   and cleaner way? It was working afterall… If you have any other idea please… 
   I’m all ears…
 *  [meraj.khattak](https://wordpress.org/support/users/merajkhattak/)
 * (@merajkhattak)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/#post-4830198)
 * I have my blog setup with latest WordPress and theme Twenty Thirteen. I added
   this code in text mode in a post on my blog:
 * `<a style="cursor:pointer;" onclick="javascript: alert('Various text according
   to situation');">*</a>`
 * and it seems to be working correctly.
 *  [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/#post-4830202)
 * You can use a plugin to hold your JS, e.g. this one [http://wordpress.org/plugins/zia3-css-js/](http://wordpress.org/plugins/zia3-css-js/)
 * E.g. to replicate this:
 *     ```
       <a style="cursor:pointer;" onclick="javascript: alert('Various text according to situation');">*</a>
       ```
   
 * You’d do this:
 *     ```
       jQuery(document).ready(function($) {
   
        $('a').click(function() {
         alert('Various text according to situation');
        });
   
       });
       ```
   
 * Let us know if you need more help with the JS
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/#post-4830203)
 * I will try the plugin and code and let you know. Thanks!
 *  [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/#post-4830204)
 * The plugin does say you can use inline JS so there may be a way to use your original
   technique
 *  Thread Starter [TabyP](https://wordpress.org/support/users/tabyp/)
 * (@tabyp)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/javascript-in-wordpress-pages/#post-4830206)
 * Actually, I don’t understand. As you can see I use an asterisk in my code. I 
   need to use that so that people will know that they have to click there. I don’t
   see where I should put the asterisk in your code.
 *  [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/#post-4830207)
 * Oh
 *  [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/#post-4830208)
 * In your code you’d have your link still:
 *     ```
       <a style="cursor:pointer;" href="#">*</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/#post-4830209)
 * Give it an ID actually
 *     ```
       <a style="cursor:pointer;" href="#" id="that-link">*</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/#post-4830210)
 * Then you use the JS to target that link:
 *     ```
       jQuery(document).ready(function($) {
   
        $('#that-link').click(function() {
         alert('Various text according to situation');
        });
   
       });
       ```
   

Viewing 15 replies - 1 through 15 (of 24 total)

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

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
