Posts Uncommon jQuery Selectors
Post
Cancel

Uncommon jQuery Selectors

ref - http://code.tutsplus.com/tutorials/uncommon-jquery-selectors–cms-25812

1
2
3
4
$("section *")         // Selects all descendants
$("section > *")       // Selects all direct descendants
$("section > * > *")   // Selects all second level descendants
$("section > * > * a") // Selects 3rd level links
1
2
3
4
5
$("section:contains('Lorem Ipsum')").each(function() {
  $(this).html(
      $(this).html().replace(/Lorem Ipsum/g, "<span class='match-o'>Lorem Ipsum</span>")
    );
});
1
2
3
4
5
6
7
8
9
10
11
12
13
*   Pellentesque [habitant morbi](dummy.html) tristique senectus.

*   Pellentesque habitant morbi tristique senectus.
  (... more list elements here ...)

*   Pellentesque habitant morbi tristique senectus.

*   Pellentesque [habitant morbi](dummy.html) tristique senectus.

$("li:has(a)").each(function(index) {
  $(this).css("color", "crimson");
});

Poor Mans jQuery

One of the functions on the ‘document’ object is the querySelectorAll function. This function brings a similar experience to vanilla JavaScript by taking selectors as a parameter.

1
2
3
4
5
6
7
8
9
10
11
//http://www.timmykokke.com/2016/05/poor-mans-jquery/

	window.$ = function (selector) { return document.querySelectorAll(selector); };

	var button = $("#btn");
	button[0].innerText="popay";
	button[0].disabled = true;

	var div = $("#myDIV");
	console.log(div);

origin - http://www.pipiscrew.com/?p=5397 uncommon-jquery-selectors

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags