Archive for the ‘javascript’ Category

React theme brakepoints

xs: Extra small devices (less than 600px) sm: Small devices (600px and up) md: Medium devices (900px and up) lg: Large devices (1200px and up) xl: Extra large devices (1536px and up) <Box sx={(theme) => ({ textAlign: ‘center’, [theme.breakpoints.up(’md’)]: { textAlign: ‘left’ }, })} > TEXT </Box> theme.breakpoints.up(‘md’) means @media (min-width: 900px) So, the above […]

Javascript match prefix

const hostname = "www.someaddress.com" console.log(!!hostname.startsWith(’www.’) ? ‘matching’ : ‘not matching’)

React js no console

PHP arrays comparision to Javascript and Java

Associative arrays in PHP = Javascript Objects written as name value pairs = Hash maps in Java

jQuery finding next “child” and previous “parent” objects

<script type="text/javascript"> … $parent = $(’#yourobject’).parent(); $child = $(’#yourobject’).children(’:first’); … </script>

Select #id with word as prefix and counter as suffix

<a id="my-favourite1"/ class="added"> <a id="my-favourite2"/ class="add"> <a id="my-favourite3"/ class="add"> <a id="my-favourite4"/ class="added"> <a id="my-favourite5"/ class="added"> <script type="text/javascript">   $(’a[id^=my-favourite]’).on(’click’, function (e) { console.log(’Clicked’); console.log(this.id); console.(this.id.removeClass(’added’).addClass(’add’)); } ); </script>

Getting “Blocked loading mixed active content” issue in Firefox

Avoid using “http://” or “https://” when loading the script in html, css or javascript. The correct example is this:   <script type="text/javascript">   $.getScript("//maps.googleapis.com/maps/api/js?key=somekey");   </script>

Detecting browser and protocol in Javascript

<script type="text/javascript">   if(/chrom(e|ium)/.test(navigator.userAgent.toLowerCase()) && location.protocol==’http:’) { alert(’Using current position in chrome restricted under http protocol’) } else if (/msie/.test(navigator.userAgent.toLowerCase())) { console.log("This browser is MSIE"); } else if (/firefox/.test(navigator.userAgent.toLowerCase())) { console.log("This browser is Firefox"); }   </script>

how-to get current hostname in javascript

window.location.host or document.location.host : you’ll get sub.domain.com:8080 or sub.domain.com:80 window.location.hostname or document.location.hostname: you’ll get sub.domain.com window.location.protocol or document.location.protocol: you’ll get http: window.location.port or document.location.port: you’ll get 8080 or 80 window.location.origin or document.location.origin: you’ll get http://sub.domain.com *