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
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
! "" is true
$() 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})