szmerek
szmerek
Reputation Top 5%
szmerek
4 Snippets  (180th place)
Published
1 Channel
Created
3 Channels
Following
Wednesday at 4:50:12 AM
Last Visit
Aug 14, 2017
Registered
97 points  (274th place)
Reputation
Junior Code Generator
Serious Code Generator
Junior Publisher
Junior Trend Maker
Junior Popular Coder
Junior Autobiographer
Serious Autobiographer

Recent Snippets See all snippets by szmerek

public by szmerek created Aug 14, 2017  263  4  5  0

OnClick without setting an attribute of the link

//<div id="dog" >Woow woow</div>


    (function() {
        document.getElementById("dog").onclick = function() { 
            alert('fuf fuf'); 
        };
    })();																								
;

public by szmerek created Aug 20, 2017  161  0  3  0

Remove part of a string before specified character

//remove string before '&' if want to include character '&' then 'indexOf("&") + 0'
var str = "black&white";
str = str.substring(str.indexOf("&") + 1);

//or use regex
var str = "black&white";
str = /&(.+)/.exec(str)[1];

// or use .split() and .pop() 
var str = "black&white";
str = str.split("&").pop();						
;

public by szmerek created Aug 20, 2017  142  1  3  0

Check whether a string matches a regex

//RegExp allows to inject variable values into the regex string
var str = "sample1";
var re = new RegExp("^([a-z0-9]{5,})$");
if (re.test(str)) {
    console.log("valid");
} else {
    console.log("invalid");
}					
;

public by szmerek created Aug 14, 2017  140  0  4  0

Hide element(s) by class

Some examples for hiding the class.
//Ex 
//<div class="appBanner">appbanner</div> 

document.getElementsByClassName('appBanner')[0].style.visibility = 'hidden';

//change the style rules of all elements matching the class

[].forEach.call(document.querySelectorAll('.appBanner'), function (el) {
  el.style.visibility = 'hidden';
});

//If for...of is available then use

for (let el of document.querySelectorAll('.appBanner')) el.style.visibility = 'hidden';

//And the other one

Array.filter( document.getElementsByClassName('appBanner'), function(elem){ elem.style.visibility = 'hidden'; });

//and the last one

var appBanners = document.getElementsByClassName('appBanner'), i;

for (i = 0; i < appBanners.length; i += 1) {
    appBanners[i].style.display = 'none';
}																								
;