forked from elmerland/js_intro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
48 lines (37 loc) · 1.33 KB
/
basic.js
File metadata and controls
48 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* global $ */
'use strict';
var global = window.global_var = {}; //get the open window in a browser, get the global variables, set all variables to nothing
global.sample_01 = function() {
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var sum = 0;
for (var i = 0; i < arr.length; i++) {
sum += arr[i];
}
return "Result: " + sum;
};
global.sample_02 = function() {
$('.sample-02 .output').css('border', '2px solid blue');
};
global.sample_03 = function() {
$('.sample-03 .output').html('Click count: <span class="counter-div">0</span>'); //Set the HTML contents of each element in the set of matched elements.
$('.sample-03 .my-button').on('click', global.increase_counter); //Attach an event handler function for one or more events to the selected elements.
};
global.counter = 0;
global.increase_counter = function() {
global.counter++;
$('.sample-03 .output .counter-div').html(global.counter);
};
global.sample_04 = function() {
$.ajax({
url: "http://edwardmcenrue.com/",
dataType: 'text',
success: function(data) {
console.log($(data).find('h2')[0].firstChild.textContent);
$('.sample-04 .output').html("I am a: " + $(data).find('h2')[0].firstChild.textContent.toString());
}
});
};
$('.sample-01 .output').html(global.sample_01());
global.sample_02();
global.sample_03();
global.sample_04();