If testcol is invalid, no change will occur. Step 4: Check to see if the color actually got changed. Step 3: Set the border color to the color you aren't sure about. The code might look something like this: e=document.getElementbyId('mydiv') Step 2: Set the border color to an empty string. The div can be positioned off screen or it can be any div on your page that doesn't use the borders. Step 1: Create a div with border-style set to none. Let the browswer do the the work for you. After several attempts I came up with a fairly clean solution. │ Radix │ Characters │ Prefix │ Will output 27 │ Now, Number() doesn't take a radix parameter, but luckily, you can prefix number literals to get a number in other radii. Number(), on the other hand, will only parse if the whole string matches the radix. This means it could parse strings like 'AAXXCC', because it starts with 'AA'. ParseInt() will parse from the beginning of the string until it reaches a character that isn't included in the radix ( 16). This answer used to throw false positives because instead of Number('0x' + hex), it used parseInt(hex, 16). IsHexColor = hex => typeof hex = 'string' & hex.length = 6 & !isNaN(Number('0x' + hex))Ĭonsole.log(isHexColor('AABBCC')) // trueĬonsole.log(isHexColor('AABBCC11')) // falseĬonsole.log(isHexColor('XXBBCC')) // falseĬonsole.log(isHexColor('AAXXCC')) // false
0 Comments
Leave a Reply. |