I just started learning jQuery and I'm watching video tutorials and trying to find different ways to accomplish things than in the video tutorial for learning purposes.
I have two buttons, Day and Night. If I click Day, I want the Day button to be disabled and to load the day style sheet. If I click Night, I want to load the Night stylesheet and disable the Night button, but then enable the Day button.
Bear with me, here's my code, ihavenoideawhatimdoing.jpg. This isn't my full code, only posted relevant code.
<head>
<link rel="stylesheet" href="day.css">
</head>
<button data-file="day">Day</button>
<button data-file="night">Night</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
// self executing function
(function() {
var link = $('link');
var button = $('button');
var $this = $(this);
if (button.data('file', 'day').click()) {
link.attr('href', 'night.css');
$this.attr('disabled');
// code to enable night button, not sure how
}
else (button.data('file', 'night').click()) {
link.attr('href', 'day.css');
$this.attr('disabled');
// code to enable the day button, not sure how
}
})();
</script>
Also, another question.
(function() {
// code
})();
Will that function execute upon page load, I mean any code within that function? I think the guy in the video called it an autonomous function.
Thanks!