<p id="myid">some content</p>
#myid::after {
display:block;
width: 100px;
height: 40px;
color: blue;
content: "Hello world";
}
#myid {
color: red;
}
var color = window.getComputedStyle(document.querySelector('#myid'), ':after').getPropertyValue('color')
var content = window.getComputedStyle(document.querySelector('#myid'), ':after').getPropertyValue('content')
console.log(color, content) // outputs the color and content of the pseudo-element
/**
* @description URL parsing using native JS engine approach
* @param {string} url - URL string
* @returns {object} parsed data
*/
function parseURL(url) {
var parser = document.createElement('a');
parser.href = url;
return {
protocol : parser.protocol, // => "http:"
hostname : parser.hostname, // => "domain.com"
port : parser.port, // => "8000"
pathname : parser.pathname, // => "/path/"
search : parser.search, // => "?search=test"
hash : parser.hash, // => "#hash"
host : parser.host // => "domain.com:8000"
}
}
console.dir(parseURL("http://domain.com:8000/path/?search=test&bar=1&bar=2&key1=val1#hash"));
var fib = function (_) {
for(_=[+[],++[[]][+[]],+[],_],_[++[++[++[[]][+[]]][+[]]][+[]]]=(((_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]]))&(((--[[]][+[]])>>>(++[[]][+[]]))))===(_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]])))?(_[++[++[[]][+[]]][+[]]]=++[[]][+[]],_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]])):+[];_[++[++[++[[]][+[]]][+[]]][+[]]]--;_[+[]]=(_[++[[]][+[]]]=_[++[++[[]][+[]]][+[]]]=_[+[]]+_[++[[]][+[]]])-_[+[]]);
return _[++[++[[]][+[]]][+[]]];
}
console.assert(fib(-1) === 0);
console.assert(fib(0) === 0);
console.assert(fib(1) === 1);
console.assert(fib(2) === 1);
console.assert(fib(3) === 2);
console.assert(fib(4) === 3);
console.assert(fib(5) === 5);
console.assert(fib(6) === 8);
console.assert(fib(7) === 13);
console.assert(fib(32) === 2178309);
console.assert(fib(46) === 1836311903);
console.assert(fib(47) === 2971215073);
console.assert(fib(63) === 6557470319842);
console.log('done!');
var someVar = 0;
alert(someVar == false); //evaluates true
alert(false == false); //evaluates true, of course
alert(someVar === false); //evaluates false - someVar is a number, not a legitimate boolean
function ReplaceByDashes(string){
return string.replace(/\s/g,'-');
}
// run it
var string = "Hello my beautiful world!";
string=ReplaceByDashes(string);
alert(string);
if(typeof String.prototype.rbd==='undefined'){ // we have to check if someone hasn't added it already
String.prototype.rbd = function(){
return this.replace(/\s/g,'-');
}
}
// run it
var string = "Hello my beautiful world!";
string=string.rbd();
alert(string);
String.prototype.ucFirst = function () {
return (this.substr(0,1).toUpperCase() + this.substr(1,this.length));
}
function print_r(theObj){
if(theObj.constructor == Array ||
theObj.constructor == Object){
document.write("<ul>")
for(var p in theObj){
if(theObj[p].constructor == Array||
theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
document.write("<ul>")
print_r(theObj[p]);
document.write("</ul>")
} else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
}
}
document.write("</ul>")
}
}