Title: How to apply java-script function to title?
Last modified: August 22, 2016

---

# How to apply java-script function to title?

 *  [whoiam](https://wordpress.org/support/users/whoiam/)
 * (@whoiam)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/how-to-apply-java-script-function-to-title/)
 * I would like to implement function to .site-title .
    I expect it will change 
   color dynamically.
 * What is a proper way to call function and apply that to class=”site-title”
    `
   randomColor(); // Returned a random color as a hex string`
 * to call [java-script](https://raw.githubusercontent.com/davidmerfield/randomColor/master/randomColor.js)
   function

Viewing 1 replies (of 1 total)

 *  [David Gwyer](https://wordpress.org/support/users/dgwyer/)
 * (@dgwyer)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/how-to-apply-java-script-function-to-title/#post-5189758)
 * This should work. Try adding to a post or page to test:
 *     ```
       <script>
       jQuery(document).ready(function($) {
         r = Math.floor(Math.random() * (256));
         g = Math.floor(Math.random() * (256));
         b = Math.floor(Math.random() * (256));
         $('#site-title a').css('color', 'rgb('+r+','+g+','+b+')' );
       });
       </script>
       ```
   
 * This works if your theme implements the site-title as a an ID, so if your theme
   has it as a class you’ll need to update your CSS selector as necessary.
 * Also, once you have this working you should add it to a JS file and enqueue it
   if you want it to apply to all pages.

Viewing 1 replies (of 1 total)

The topic ‘How to apply java-script function to title?’ is closed to new replies.

## Tags

 * [color](https://wordpress.org/support/topic-tag/color/)
 * [css](https://wordpress.org/support/topic-tag/css/)
 * [java-script](https://wordpress.org/support/topic-tag/java-script/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [David Gwyer](https://wordpress.org/support/users/dgwyer/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/how-to-apply-java-script-function-to-title/#post-5189758)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
