-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1326 lines (1311 loc) · 50.3 KB
/
index.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="jquery, ldom, lightweight, dom, javascript, data, manipulation, web, web app, library">
<meta name="description" content="A Lightweight JavaScript library to interact with the browser DOM.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#ff8800">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-title" content="LDOM">
<meta name="application-name" content="LDOM">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ff8800">
<meta property="og:title" content="Lightweight DOM Library">
<meta property="og:url" content="http://lightweightdom.com">
<meta property="og:description" content="A Lightweight JavaScript library to interact with the browser DOM.">
<meta property="og:image" content="http://lightweightdom.com/feather.png">
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@JasonONeillCTG" />
<meta name="twitter:title" content="Lightweight DOM Library" />
<meta name="twitter:description" content="A Lightweight JavaScript library to interact with the browser DOM." />
<meta name="twitter:image" content="http://lightweightdom.com/feather.png" />
<title>LDOM API Documentation</title>
<link href="resources/main.css" rel="stylesheet" />
<link href="resources/prism/prism.css" rel="stylesheet" />
<style>
.github-corner:hover .octo-arm {
animation: octocat-wave 560ms ease-in-out
}
@keyframes octocat-wave {
0%,
100% {
transform: rotate(0)
}
20%,
60% {
transform: rotate(-25deg)
}
40%,
80% {
transform: rotate(10deg)
}
}
</style>
</head>
<body>
<a href="https://github.com/CreativeTechGuy/LDOM" target="_blank" class="github-corner" aria-label="View source on Github" title="View source on Github"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
</svg></a>
<img id="menu" src="resources/menu.svg" alt="Menu Open" />
<nav>
<img id="close" src="resources/close.svg" alt="Menu Close" />
<h3 class="nav-title">Menu</h3>
<div>
</div>
<footer>Copyright <span id="copyrightYearNav"></span> <a href="https://creativetechguy.com" target="_blank">Jason O'Neill</a></footer>
<script>
document.getElementById("copyrightYearNav").innerText = new Date().getFullYear();
</script>
</nav>
<main>
<header>
<h1><a href="/" class="title-link">LDOM API Documentation</a></h1>
</header>
<section>
<h2 class="section-title" id="getting-started">Getting Started</h2>
<div class="p-like">
LDOM is a Lightweight (about 8% of the size of jQuery) way to interact with the browser DOM (Document Object Model). To start development, download the development version and include it in your webpage.
<a class="large-button" id="download">Download ldom.dev.js</a>
<pre><code class="language-html"><script src="ldom.dev.js"></script></code></pre> Once you are ready for production, you can run <code class="language-js">getLDOMFunctionUsage()</code> in your browser console. This will show which features of LDOM you have used so far on the current page. Then you can customize your LDOM download to only include the features you need!<br>
<em>Be sure to interact with all of the features of your webpage to get an accurate usage list.</em>
<a class="large-button" href="customizer">Customize ldom.min.js</a>
</div>
<div class="p-like">
If you are familiar with jQuery, then LDOM will feel very similar. In many common use cases, LDOM can simply be a drop-in replacement to jQuery without any problems. LDOM is able to startup over 10x faster due to it's small size and simple code. One way that LDOM is so much smaller and simpler than jQuery is that it doesn't support all of the ancient browsers that jQuery does. That being said, by using LDOM, here are the minimum browser versions that are supported. (Basically any browser since 2013)
<table>
<tr>
<th>Browser</th>
<th>Version</th>
</tr>
<tr>
<td>Chrome</td>
<td>29</td>
</tr>
<tr>
<td>Firefox</td>
<td>23</td>
</tr>
<tr>
<td>Safari</td>
<td>6</td>
</tr>
<tr>
<td>IE</td>
<td>9</td>
</tr>
<tr>
<td>Edge</td>
<td>all</td>
</tr>
<tr>
<td>Opera</td>
<td>12</td>
</tr>
</table>
</div>
</section>
<section>
<h2 class="section-title" id="ldom-vs-jquery">LDOM vs jQuery</h2>
<div class="p-like">
There is never one correct library for all situations. It's important to know the pros and cons to help you make the best decision for your use-case.<br>
<br>
<h4 class="doc-title">LDOM > jQuery</h4>
<ul>
<li>Smaller library size allows for faster load times on slower networks.<br>(8% of the size of jQuery)</li>
<li>Smaller/simpler library enables faster parse/compile time and therefore your code will start sooner.<br>(10x faster startup time)</li>
<li>Customizable library lets you make the library even smaller if you don't want certain features.<br>(85% possible size reduction)</li>
<li>Faster DOM Element creation.</li>
<li>All LDOM code clearly maps to VanillaJS code. No complicated wrappers or replacements of default DOM behavior.</li>
<li>Better library source code readability.</li>
</ul>
<h4 class="doc-title">LDOM < jQuery</h4>
<ul>
<li>Less browser support.</li>
<li>Slower performance in extremely heavy tasks.</li>
</ul>
</div>
</section>
<section>
<h2 class="section-title" id="example-usage">Example Usage</h2>
<h3 class="section-title">Comparison between LDOM and Vanilla JavaScript</h3>
<div class="doc-box">
<h3>Set the text of all buttons.</h3>
<h4 class="doc-title">LDOM</h4>
<pre><code class="language-js">$("button").text("I am a Button");</code></pre>
<h4 class="doc-title">Vanilla JavaScript</h4>
<pre><code class="language-js">var buttons = document.querySelectorAll("button");
for (var i = 0; i < buttons.length; i++) {
buttons[i].innerText = "I am a Button";
}</code></pre>
</div>
<div class="doc-box">
<h3>Add a class to all parents of buttons.</h3>
<h4 class="doc-title">LDOM</h4>
<pre><code class="language-js">$("button").parent().addClass("button-parent");</code></pre>
<h4 class="doc-title">Vanilla JavaScript</h4>
<pre><code class="language-js">var buttons = document.querySelectorAll("button");
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].parentNode.className.split(" ").indexOf("button-parent") === -1) {
buttons[i].parentNode.className += " " + "button-parent";
}
}</code></pre>
</div>
<div class="doc-box">
<h3>Add a click event to all buttons. Remove that event from a certain button.</h3>
<h4 class="doc-title">LDOM</h4>
<pre><code class="language-js">var activateButtonEventId = $("button").on("click", function() {
this.addClass("button-active");
});
$("button").eq(1).off(activateButtonEventId);</code></pre>
<h4 class="doc-title">Vanilla JavaScript</h4>
<pre><code class="language-js">var buttons = document.querySelectorAll("button");
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", addButtonActiveClass);
}
buttons[1].removeEventListener("click", addButtonActiveClass);
function addButtonActiveClass(){
if (buttons[i].className.split(" ").indexOf("button-active") === -1) {
buttons[i].className += " " + "button-active";
}
}</code></pre>
</div>
<div class="doc-box">
<h3>Create a text element and insert it after each button.</h3>
<h4 class="doc-title">LDOM</h4>
<pre><code class="language-js">$("<text>")
.css("text-align", "center")
.text("Click the button above!")
.insertAfter($("button"));</code></pre>
<h4 class="doc-title">Vanilla JavaScript</h4>
<pre><code class="language-js">var textElem = document.createElement("text");
textElem.style.textAlign = "center";
textElem.innerText = "Click the button above!";
var buttons = document.querySelectorAll("button");
for (var i = 0; i < buttons.length; i++) {
buttons[i].parentNode.insertBefore(textElem.cloneNode(true), buttons[i].nextSibling);
}</code></pre>
</div>
<div class="doc-box">
<h3>The side menu on this page was even generated with the following code!</h3>
<h4 class="doc-title">LDOM</h4>
<pre><code class="language-js">var nav = $("nav");
$("section").each(function () {
var header = this.find(".section-title").first();
nav.appendChild(
$("<a>")
.addClass("nav-link")
.prop("href", "#" + header.attr("id"))
.text(header.text())
);
});</code></pre>
<h4 class="doc-title">Vanilla JavaScript</h4>
<pre><code class="language-js">var nav = document.querySelector("nav");
var sections = document.querySelectorAll("section");
for (var i = 0; i < sections.length; i++) {
var header = sections[i].querySelector(".section-title");
var a = document.createElement("a");
a.className = "nav-link";
a.href = "#" + header.id;
a.innerText = header.innerText;
nav.appendChild(a);
}
</code></pre>
</div>
<h3>As you can see, LDOM is an extremely powerful DOM manipulation tool.</h3>
</section>
<section>
<h2 class="section-title" id="constructor">$(...)</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">$(selector)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>selector</dt>
<dd>A string containing a selector to match elements against.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>An object on which functions can be executed on the element(s) it contains.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button")</code></pre>
<pre><code class="language-js">$(".section-title")</code></pre>
<pre><code class="language-js">$("a[href='index.html']")</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">$(DOMElement)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>DOMElement</dt>
<dd>A reference to one or more vanilla DOM Elements.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>An object on which functions can be executed on the element(s) it contains.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$(document.getElementById("#title"))</code></pre>
<pre><code class="language-js">$(document.querySelectorAll("button"))</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">$(htmlTag)</code></pre>
Used to create a new HTML element.
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>htmlTag</dt>
<dd>An HTML opening tag with angled brackets.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>An object on which functions can be executed on the element(s) it contains.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("<button>")</code></pre>
<pre><code class="language-js">$("<br>")</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="each">.each()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.each(function)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>function</dt>
<dd>A <code class="language-js">function(index)</code> which gets called on for each element of the LDOM Object. <code class="language-js">this</code> refers to an LDOM Object for the current element. You can optionally <code class="language-js">return false;</code> from the function to break out of the loop early.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").each(function(){
console.log(this.get(0));
});</code></pre>
<pre><code class="language-js">$("p").each(function(i){
this.text("Paragraph #" + i);
});</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.each(function, reverse)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>function</dt>
<dd>A <code class="language-js">function(index)</code> which gets called on for each element of the LDOM Object. <code class="language-js">this</code> refers to an LDOM Object for the current element. You can optionally <code class="language-js">return false;</code> from the function to break out of the loop early.</dd>
<dt>reverse</dt>
<dd>If true, then the elements will be looped through in reverse order.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").each(function(){
console.log(this.get(0));
}, true);</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="equals">.equals()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.equals(LDOMObject)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>LDOMObject</dt>
<dd>A LDOM Object to compare against the calling LDOM Object.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>Boolean</dt>
<dd>True if both LDOM Objects contain the same elements. False if not.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
Although the element order will affect the equality comparison, in most situations this will not make a difference.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("div").children().filter("h1").equals($("div>h1"))</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="find">.find()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.find(selector)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>selector</dt>
<dd>A string containing a selector to match elements against. Searches the DOM tree from the current LDOM Object's Elements.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>A new LDOM Object containing the selected elements.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("section").find("h3")</code></pre>
<pre><code class="language-js">$("p").find(".alert-text")</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="parent">.parent()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.parent()</code></pre>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>A new LDOM Object containing the parent of each element.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("p").parent()</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="children">.children()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.children()</code></pre>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>A new LDOM Object containing the children of each element.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("p").children()</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="filter">.filter()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.filter(selector)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>selector</dt>
<dd>A string containing a selector to match the LDOM Object's Elements against.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>A new LDOM Object containing the matching elements.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("div").children().filter("p")</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="first">.first()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.first()</code></pre>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>A new LDOM Object containing only the first element.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("p").first()</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="last">.last()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.last()</code></pre>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>A new LDOM Object containing only the last element.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("p").last()</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="eq">.eq()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.eq(index)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>index</dt>
<dd>The index of the LDOM Element you wish to retrieve. Negative indexes count from the end of the list.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>A new LDOM Object containing only the first element.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$(".header-title").eq(3)</code></pre>
<pre><code class="language-js">$(".header-title").eq(-1)</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="get">.get()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.get()</code></pre>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>DOM Element Array</dt>
<dd>An array of vanilla DOM Elements from the LDOM Object.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").get()</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.get(index)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>index</dt>
<dd>The index of the LDOM Element you wish to retrieve. Negative indexes count from the end of the list.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>DOM Element</dt>
<dd>A single vanilla DOM Element from the LDOM Object specified by the index.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
Will return <code class="language-js">null</code> if there is no element at the specified index.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$(".header-title").get(3)</code></pre>
<pre><code class="language-js">$(".header-title").get(-1)</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="on">.on()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.on(eventName, handler)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>eventName</dt>
<dd>The event type you want to listen for.</dd>
<dt>handler</dt>
<dd>The function to be executed when the event is triggered. <code class="language-js">this</code> refers to an LDOM Object for the element that triggered the event.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>eventId</dt>
<dd>A number representing the event that was added. Can be used to remove that event with <code class="language-js">off</code>.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">var buttonClickEventId = $("button").on("click", function(){
this.addClass("activated");
});</code></pre>
<pre><code class="language-js">$("a").on("customEvent", function(){
console.log("Custom Event Triggered", this);
});</code></pre>
<pre><code class="language-js">$("h3").on("click", changeColor);
function changeColor() {
this.css("color", "#FF0000");
}</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="off">.off()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.off()</code></pre>
Removes all event handlers added with <code class="language-js">.on()</code>.
<h3 class="doc-title">Return Value</h3>
<dl>
<dt><code class="language-js">undefined</code></dt>
<dd>There is no return value.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("a").off();</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.off(eventName)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>eventName</dt>
<dd>The event type you want to remove all handlers for.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt><code class="language-js">undefined</code></dt>
<dd>There is no return value.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("a").off("customEvent");</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.off(eventId)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>eventId</dt>
<dd>The ID returned from .on() of the event to remove.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt><code class="language-js">undefined</code></dt>
<dd>There is no return value.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").off(buttonClickEventId);</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="trigger">.trigger()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.trigger(eventName)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>eventName</dt>
<dd>The event type to send.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").trigger("click");</code></pre>
<pre><code class="language-js">$("a").trigger("customEvent");</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.trigger(eventName, data)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>eventName</dt>
<dd>The event type to send.</dd>
<dt>data</dt>
<dd>An object of data to attach to the event.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").trigger("click", { x: 10, y: 25 });</code></pre>
<pre><code class="language-js">$("a").trigger("customEvent", { arr: [1, 5, 10] });</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="hide">.hide()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.hide()</code></pre> Hides the elements and stores their previous display style. Style can be restored with <code class="language-js">.show()</code>.
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").hide();</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="show">.show()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.show()</code></pre> Returns the elements to the display style that they had before <code class="language-js">.hide()</code> was called.
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").show();</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="toggle">.toggle()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.toggle()</code></pre>
Will show the matching elements if it's hidden or hide if it's visible.
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").toggle();</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.toggle(show)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>show</dt>
<dd>If true, elements will be shown regardless of current state. If false, elements will be hidden regardless of current state.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$(".title").toggle(true);</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="css">.css()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.css(property)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>property</dt>
<dd>Name of the CSS property to get.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>String</dt>
<dd>The computed value of the element's style.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
If the LDOM Object contains multiple elements, this will only return the value of the first element. Use <code class="language-js">.eq()</code>, <code class="language-js">.first()</code> or <code class="language-js">.last()</code> to reduce to one element.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").css("font-size");</code></pre>
<pre><code class="language-js">$("button").last().css("font-size");</code></pre>
<pre><code class="language-js">$("button").eq(2).css("font-size");</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.css(property, value)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>property</dt>
<dd>Name of the CSS property to set.</dd>
<dt>value</dt>
<dd>The value to set the CSS property to.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").css("font-size", "35px");</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.css(property, value, isImportant)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>property</dt>
<dd>Name of the CSS property to set.</dd>
<dt>value</dt>
<dd>The value to set the CSS property to.</dd>
<dt>isImportant</dt>
<dd>If true, the style will be marked with "!important" specificity.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").css("display", "inline-block", true);</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="html">.html()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.html()</code></pre>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>String</dt>
<dd>The element's inner HTML.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
If the LDOM Object contains multiple elements, this will only return the value of the first element. Use <code class="language-js">.eq()</code>, <code class="language-js">.first()</code> or <code class="language-js">.last()</code> to reduce to one element.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").html();</code></pre>
<pre><code class="language-js">$("button").last().html();</code></pre>
<pre><code class="language-js">$("button").eq(2).html();</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.html(htmlString)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>htmlString</dt>
<dd>String containing the HTML content to set.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").html("<a href='index'>Home</a>");</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="outerHTML">.outerHTML()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.outerHTML()</code></pre>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>String</dt>
<dd>The element's outer HTML.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
If the LDOM Object contains multiple elements, this will only return the value of the first element. Use <code class="language-js">.eq()</code>, <code class="language-js">.first()</code> or <code class="language-js">.last()</code> to reduce to one element.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").outerHTML();</code></pre>
<pre><code class="language-js">$("button").last().outerHTML();</code></pre>
<pre><code class="language-js">$("button").eq(2).outerHTML();</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.outerHTML(htmlString)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>htmlString</dt>
<dd>String containing the outer HTML to set.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt><code class="language-js">undefined</code></dt>
<dd>There is no return value.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
Outer HTML replaces the entire element; therefore will break event listeners and any LDOM Objects that had reference to that element. It's not recommend to set outer HTML if you can help it.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("a").outerHTML("<button>I'm now a button!</button>");</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="text">.text()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.text()</code></pre>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>String</dt>
<dd>The element's text.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
If the LDOM Object contains multiple elements, this will only return the value of the first element. Use <code class="language-js">.eq()</code>, <code class="language-js">.first()</code> or <code class="language-js">.last()</code> to reduce to one element.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").text();</code></pre>
<pre><code class="language-js">$("button").last().text();</code></pre>
<pre><code class="language-js">$("button").eq(2).text();</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.text(textString)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>textString</dt>
<dd>String containing the text content to set.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").text("Click me!");</code></pre>
</div>
</div>
</section>
<section>
<h2 class="section-title" id="prop">.prop()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.prop(propertyName)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>propertyName</dt>
<dd>Name of the HTML property to get.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>String</dt>
<dd>The element's HTML property value.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
If the LDOM Object contains multiple elements, this will only return the value of the first element. Use <code class="language-js">.eq()</code>, <code class="language-js">.first()</code> or <code class="language-js">.last()</code> to reduce to one element.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("input").prop("readOnly");</code></pre>
<pre><code class="language-js">$("input").last().prop("value");</code></pre>
<pre><code class="language-js">$("input").eq(2).prop("required");</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.prop(propertyName, value)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>propertyName</dt>
<dd>Name of the HTML property to set.</dd>
<dt>value</dt>
<dd>String containing the property value to set.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("input").prop("readOnly", "true");</code></pre>
<pre><code class="language-js">$("input").prop("value", "Enter Phone Number");</code></pre>
</div>
<h3 class="doc-title">Attr vs Prop</h3>
<div>
Often times <code class="language-js">.attr()</code> and <code class="language-js">.prop()</code> can be used interchangeably. In general, <code class="language-js">.attr()</code> should be used to get/set the value as literally written in the HTML document. <code class="language-js">.prop()</code> should be used to get/set the computed value as seen by JavaScript's DOM tree.
</div>
</div>
</section>
<section>
<h2 class="section-title" id="attr">.attr()</h2>
<div class="p-like">
<div class="doc-box">
<pre><code class="language-js">.attr(attributeName)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>attributeName</dt>
<dd>Name of the HTML attribute to get.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>String</dt>
<dd>The element's HTML attribute value.</dd>
</dl>
<br>
<h3 class="doc-title">Information</h3>
<div>
If the LDOM Object contains multiple elements, this will only return the value of the first element. Use <code class="language-js">.eq()</code>, <code class="language-js">.first()</code> or <code class="language-js">.last()</code> to reduce to one element.
</div>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("input").attr("aria-label");</code></pre>
<pre><code class="language-js">$("input").last().attr("title");</code></pre>
<pre><code class="language-js">$("input").eq(2).attr("data-meta");</code></pre>
</div>
<div class="doc-box">
<pre><code class="language-js">.attr(attributeName, value)</code></pre>
<h3 class="doc-title">Parameters</h3>
<dl>
<dt>attributeName</dt>
<dd>Name of the HTML attribute to set.</dd>
<dt>value</dt>
<dd>String containing the attribute value to set.</dd>
</dl>
<h3 class="doc-title">Return Value</h3>
<dl>
<dt>LDOM Object</dt>
<dd>The existing LDOM Object is returned to allow function chaining.</dd>
</dl>
<br>
<h3 class="doc-title">Examples</h3>
<pre><code class="language-js">$("button").attr("title", "You can click me!");</code></pre>
</div>