Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
The Snippets of JavaScript
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
LICENSE
Makefile
README.md
snippets-tests.html
snippets-tests.js
snippets.js

README.md

The Snippets of JavaScript

Does not depend on any libraries and implementation of the minimum.

IMPORTANT: All functions does not check parameters that applied. It's need to apply valid parameters.

Functions

indexOf(arr, search)

var i = 2;
var arr = [0, 1, 2, 3, 4];
var index = indexOf(arr, i);

getElementsByClassName(className, root)

<ul id="parent">
  <li class="child"></li>
  <li class="child"></li>
  <li class="child"></li>
</ul>
<script>
var parent = document.getElementById('parent');
var children = getElementsByClassName('child', parent);
</script>

querySelector(selector, root)

<ul id="parent">
  <li class="child"></li>
  <li class="child"></li>
  <li class="child"></li>
</ul>
<script>
var element = querySelector('#parent');
</script>

querySelectorAll(selector, root)

<ul id="parent">
  <li class="child"></li>
  <li class="child"></li>
  <li class="child"></li>
</ul>
<script>
var elements = querySelectorAll('.child');
</script>

contains(node, needle)

<ul id="parent">
  <li id="child1"></li>
  <li id="child2"></li>
  <li id="child3"></li>
</ul>
<script>
var parent = querySelector('#parent');
var child1 = querySelector('#child1');
if (contains(parent, child1)) {
  alert('contains!');
}
</script>

Support Browsers

  • Internet Explorer 6+
  • Mozilla Firefox 3.6+
  • Google Chrome
  • Safari 5+
  • Opera 11+

Author

License

This code is available under the BSD license.

Something went wrong with that request. Please try again.