Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9077653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:25:23+00:00 2026-06-16T19:25:23+00:00

In the snippet provider there is a simple function which does the following. Looks

  • 0

In the snippet provider there is a simple function which does the following.

  • Looks for e-mail in the input field, and>> pushes e-mail to md5 hash, and>> generates a url of a Gravatar which is then embedded into a class via fadeIn();

    $(document).ready(function(){
    
        $('.email').on('change', function(){
            var hash = hex_md5($('.email').val()); 
            $('.gravatar').attr('src', 'http://www.gravatar.com/avatar/' + hash + '?s=120').addClass('gravatar-glow').fadeIn("slow");
        });
    });
    
    
    HTML Part: <img src="" class="gravatar" style="display: none;"/>
    

The problem

  • If e-mail is deleted the class is still shown however this time its not using md5 of email but is displaying default Gravatar image.

What I want to achieve is if the input field is empty because say user choose to remove there e-mail to use a different one, I want to hide the class that was previously used instead of displaying a Default Gravatar image.

And here is the jQuery code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:25:24+00:00Added an answer on June 16, 2026 at 7:25 pm

    You can use toggleClass, this method accepts a boolean value, if the switch is true, class is added otherwise the class is removed.

    .toggleClass( className, switch )
    

    $('.email').on('change', function(){
        var val = $.trim(this.value), hash = hex_md5(val); 
        $('#element').prop('src', function(){
             return val.length
                    ? 'http://www.gravatar.com/avatar/' + hash + '?s=120'
                    : 'default path to the image'
        }).toggleClass('.gravatar', val.length)
          .fadeIn("slow");
    });
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
The permission/authentication documentation for Django 1.4 provides the following snippet for creating custom permissions
Trying to understand the math of this code snippet. A token is provided which
Following snippet attempts to write the name of directories and files present in some
I am reading a book on trees. here is the text snippet. There are
I am trying to setup a simple snippet in SQL Server management studio. When
This is the code snippet that the developer site has provided for getting a
Snippet from a SQL query (using SQL Server 2008 R2): , CONVERT (VARCHAR(10), s.ENTER_DATE,
Snippet of my CSS: #wrapper div.box { background: url('box-bg.png') left top repeat-y; } #wrapper
Snippet from deploy.rb task :prod1 do set :deploy_to, /home/project/src/prod1 end task :prod2 do set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.