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 3789330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:08:25+00:00 2026-05-19T12:08:25+00:00

I just started looking into jQuery yesterday, before this I programmed in only PHP.

  • 0

I just started looking into jQuery yesterday, before this I programmed in only PHP. So the best way I can explain what I’m looking for, is a way to say “else” in jQuery.

Suppose I have the following:

$('input').click(function() {
    $(this).addClass('fieldBorder');
});

How can I say “when the input field is clicked out of, then remove the class fieldBorder”. I see a lot of ways to do things in jQuery but how does one say the opposite when the user’s action has transpired.

Another example:

$('a.clickMe').mouseover(function() {
    $('hiddenMessage').show();
});

In the above example, is the only way to hide the hidden message once the user has ceased mousing over the link to use something like this:

$('a.clickMe').mouseout(function() {
    $('hiddenMessage').hide();
});

I get the nagging feeling that there is a much simpler/less redundant way of doing it. Is that what a “call back” is?

EDIT

From the answers I’m guessing there is no easy way to do it. However I did notice in the ajax function you have this:

$.ajax({

type: 'get'
url: 'script.php',
data: 'foo=boo';
success: function() {

alert('it worked');

}, error: function() {

alert('it did not work');

}

})

which that , something else: function() part existed for all other jQuery code as well.

  • 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-05-19T12:08:26+00:00Added an answer on May 19, 2026 at 12:08 pm

    That’s not really a jQuery thing, it’s about how the browser handles events.

    An element can have focus. If it can, if can also lose that focus. The event that is fired when an element loses focus is the blur event.

    Depending on what kind of element you’re talking about though, it may never gain focus, even if clicked upon, or it may lose focus at a different time than is convenient for you. In that case you may simply want to listen to when the user clicks on the document or <body>, and determine if you need to do something.


    AJAX success and error handlers are not quite the same thing as event handling. At some specific point, an AJAX request either succeeds or fails, it’s a one-time if..else. Events are more complex though, any event may fire at any time, and there isn’t necessarily an “opposite” event. What’s the opposite of a click? There’s no such thing as unclick. There’s only a click on a different element.

    There are certain idioms on how to build specific behavior using these constraints. Like, display some element when clicking on a link, and hide the element when clicking on any element that’s not the link or the displayed element.

    For example, you attach a click event handler to the document, which will catch all click events. For each triggered event, you determine whether its target was some specific element or a child of that element.

    For an alternative, you have to understand that events bubble up. When you click on some element, the click event of that element will be triggered. Then the click event of the element’s parent will be triggered and so on, until the top element is reached (that’s how the document catches all events as well).
    You can attach an event to the document that does something. You also attach a click event to some specific element that stops the event from bubbling up. This way, you have created the effect of “do something when clicking on anything but the specific element”.

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

Sidebar

Related Questions

There doesn't seem to be any tried and true set of best practices to
(please excuse that I didn't use aliases). I would like my query output to
I'm working on a project in C# w/ XNA, and I want to reorganize
I am playing with TFS 2010, and am trying to setup a build process
My question is about memory use and objects in actionscript 2. If I have
I have a new web app that is packaged as a WAR as part
I am using a 3rd-party rotator object, which is providing a smooth, random rotation

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.