Link to home
Start Free TrialLog in
Avatar of Simon Leung
Simon Leung

asked on

JQuery Code Enquiry

1. In the code below, what's "buttons.not(this)" means ? What does "this" refer to ?  Thx
2.  for the statement : if( !$("#formfield").val() ),  does formfield value return undefine if it is not set, and ! make the whole statement return true ?
3. What does $(function() means ?

Thx

<head>
    <link rel="stylesheet" href="day.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>

<button id="day" disabled>Day</button>
<button id="night">Night</button>

<script type="text/javascript">
    $(function() {
        var link = $('link[href="day.css"]'),
            buttons = $('button');
        buttons.on('click', function() {
            link.attr('href', this.id+'.css');
            buttons.not(this).removeAttr('disabled');
            $(this).attr('disabled', 'disabled');
        });
    });
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
2. does formfield value return undefine if it is not set, and ! make the whole statement return true ?
it return an empty string and you right
! "" is true

3. What does $(function() means ?
$() is a shorthand of $(document).ready() // <--- click the link
so
$(function() { your multiline or not code here})  
is a shorthand of
$(document).ready(function() { your multiline or not code here})