Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - document.ready equivelant in plain Javascript function

0 votes
17 views
added Dec 6, 2020 in Javascript by lcjr Second Warrant Officer (3,820 points)
function docReady(fn) {
  // checking the DOM
  if (document.readyState === "complete" || document.readyState === "interactive") {
      // call on next available tick
      setTimeout(fn, 1);
  } else {
      document.addEventListener("DOMContentLoaded", fn);
  }
} 
docReady(function() {
	// DOM is loaded and ready for manipulation 
	var text = document.getElementById("hmUrl").value;
	text = text.replace(
		/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)/g,
		'<a href="$1">$1</a>'
	);
});

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...