I'd like to have a list of all authors of a Wordpress blog to be shown as random characters, which change on mouseover to real names. I'm quite new to JavaScript and the code I have here is based on Random Text On MouseOver And On MouseLeave Show The Real Text, as Amir was looking for almost the same thing as me, only the other way around.
I want a unique string of random characters for each name, and I know I shouldn't use the class attribute in order to do that, but how can I use id without having to list all the names manually?
Secondly, the random character string isn't showing up until you first mouseover the text because I use mouseenter, but what is the proper way to do this?
Thanks in advance!
Javascript:
$(document).ready(function(){
var change_this = $( ".change_this" ).text();
$( ".change_this" ).mouseenter(function() {
$( ".change_this" ).text( change_this );
});
$( ".change_this" ).mouseleave(function() {
var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%$';
for(var i=0; i < $( ".change_this" ).text().length; i++)
{
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
$( ".change_this" ).text( text );
});
})
PHP (I just show everything):
foreach ( $blogusers as $user ) {
echo '<p><a href="http://www.untitled-jpg.nl/author/' . esc_html( $user->user_login ) . '/"><span class="x">' . esc_html( $user->display_name ) . '.jpg</span></a></p>';
}
?>
For testing the Javascript: http://jsfiddle.net/pqkdx1sn/1/#&togetherjs=4GUpxUpfvB