Uncommon jQuery Selectors

Costas

Administrator
Staff member
ref - http://code.tutsplus.com/tutorials/uncommon-jquery-selectors--cms-25812
JavaScript:
$("section *")         // Selects all descendants
$("section > *")       // Selects all direct descendants
$("section > * > *")   // Selects all second level descendants
$("section > * > * a") // Selects 3rd level links

JavaScript:
$("section:contains('Lorem Ipsum')").each(function() {
  $(this).html(
      $(this).html().replace(/Lorem Ipsum/g, "[B]Lorem Ipsum[/B]")
    );
});

JavaScript:
[LIST]
  [*]Pellentesque [url='dummy.html']habitant morbi[/url] tristique senectus.
  [*]Pellentesque habitant morbi tristique senectus.
  (... more list elements here ...)
  [*]Pellentesque habitant morbi tristique senectus.
  [*]Pellentesque [url='dummy.html']habitant morbi[/url] tristique senectus.
[/LIST]

$("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.

JavaScript:
//http://www.timmykokke.com/2016/05/poor-mans-jquery/
<script type="text/javascript">
	window.$ = function (selector) { return document.querySelectorAll(selector); };
	
	var button = $("#btn");
	button[0].innerText="popay";
	button[0].disabled = true;
	
	var div = $("#myDIV");
	console.log(div);

</script>
 
Top