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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:41:53+00:00 2026-05-17T16:41:53+00:00

Using a watermark plugin for jQuery, I’m attempting to jslint and minimize the functions

  • 0

Using a watermark plugin for jQuery, I’m attempting to jslint and minimize the functions but I’ve come across syntax I have never seen before wherein there are expressions where there really ought to be an assignment or function call:

(function($) {

    $.fn.watermark = function(css, text) {

        return this.each(function() {

            var i = $(this), w;

            i.focus(function() {
                w && !(w=0) && i.removeClass(css).data('w',0).val('');
            })
                .blur(function() {
                    !i.val() && (w=1) && i.addClass(css).data('w',1).val(text);
                })
                .closest('form').submit(function() {
                    w && i.val('');
                });

            i.blur();
        });
    };

    $.fn.removeWatermark = function() {

        return this.each(function() {

            $(this).data('w') && $(this).val('');
        });
    };
})(jQuery);

I’m specifically interested in the following lines:

w && !(w=0) && i.removeClass(css).data('w',0).val('');

and

!i.val() && (w=1) && i.addClass(css).data('w',1).val(text);

Can someone explain this shorthand and rewrite these functions in such a way that I could compare them to better to understand the shorthand myself?

Thank you.

  • 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-17T16:41:53+00:00Added an answer on May 17, 2026 at 4:41 pm

    Let’s break each of the statements you’re asking about down to their components:

    w && !(w=0) && i.removeClass(css).data('w',0).val('');
    
    • w – Is w “true”? (checking for != 0 in this case)
    • !(w=0) – Set w to 0, take the opposite of the result so the && chain continues
    • i.removeClass(css).data('w',0).val('') – Remove the class, set the data to 0 clear the value.

    !i.val() && (w=1) && i.addClass(css).data('w',1).val(text);
    
    • !i.val() – Is the input empty?
    • (w=1) – Set w to 1
    • i.addClass(css).data('w',1).val(text); – Add the class, set the data to 1 and set the text to whatever the watermark text is.

    Both of these are just statements to really cut down on code, certainly at the expense of readability. If you’re looking at a de-minified version this is very common, if you’re not and this is the original, chase the author with a salad fork, the original should be more more readable than this IMO, though it’s just fine for a minified version.

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

Sidebar

Related Questions

jQuery Version: 1.4.1 I am attempting to write a simple watermark type plugin and
I'm using this watermark plugin for jQuery. It works fine on every page except
Ok so i have a text field that uses this jQuery watermark plugin which
I am using the jquery.watermark.min.js plugin. I just recently noticed that it is submitting
I'm using the jquery plugin wordFilter: http://people.apache.org/~gmonroe/wordFilter/index.html which gives the autoSearch function, which allows
I'm using the jQuery watermarkinput plugin to place hint text inside text box input
I'm using DNN 5.4 with the default google api jquery reference: I have confirmed
I'm using watermark extenders on textboxes and an exception is being thrown from the
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have

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.