Title: Need help with onclick with shortcode
Last modified: August 21, 2016

---

# Need help with onclick with shortcode

 *  [Wolfenstein](https://wordpress.org/support/users/wolfenstein/)
 * (@wolfenstein)
 * [12 years ago](https://wordpress.org/support/topic/need-help-with-onclick-with-shortcode/)
 * Well right now I have brain lock and this should be simple.
    Basically I want
   to add a onclick event to the content in this function in which it applies a 
   css class.
 * function my_onclick_handler($atts, $content = null)
    { return “<div onclick= 
   class=’my css’ >”.do_shortcode($content).”</div>”; }
 * Thanks in advance.

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years ago](https://wordpress.org/support/topic/need-help-with-onclick-with-shortcode/#post-4904570)
 * Set the onclick attribute to call a javascript function, also output a `<script
   >` block that declares that function, so something like this (untested):
    `return"
   <div id='target' onclick='setCSS();' class='my css' >".do_shortcode($content)."
   </div><script>function setCSS(){document.getElementById('target').className='
   newClass';}</script>"`

Viewing 1 replies (of 1 total)

The topic ‘Need help with onclick with shortcode’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/need-help-with-onclick-with-shortcode/#post-4904570)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
